Jump to content

Roblox Game Development/Changing Properties

From Wikibooks, open books for an open world

Introduction

[edit | edit source]

What you are going to learn:

Learn about common Properties for the class object called "Part" and how to use them.

We will learn about several common properties.

Also note that the code provided below is meant only for one to learn about how they work. It is more effective to use the building tools to apply the properties below instead of making scripts for each part that needs properties.

Transparency

[edit | edit source]

Transparency is the clearness of a shape. The Property of Transparency is a Number Value. An example of this is the number 2. Any number for the Transparency property can be changed into any number property. However anything over the value of one would remain the same in the physical world as invisible. Transparency can be useful for creating things such as windows or invisible barriers.

Here is a small scale of Transparency:

The greater the value between 0 to 1, the more transparent the Part gets. The number 0 is related to the Part being completely visible to the user in a game. The number value 1 means that the Part would be Completely Invisible in the game.


Example Insert a Part inside Workspace if you're on Roblox Studio now please.


Let's say there is the class object called "Part" in your Workspace and we want to change the transparency of the Part. Here is how we do it:


game.Workspace.Part.Transparency = 1


This is the line of code we need to achieve what we want to be done.

game.Workspace.Part gives you access to the Part that is in Workspace. All you have to do is add on Transparency and set it's value to the number value "1" so it will become invisible.


Now run the script.


If it was successful you have completed learning about transparency.

A second method is to use the “transparency” field in a part’s Properties menu, simply type a value from 0-1 to change the transparency.

Anchored

[edit | edit source]

Anchored is a state when a part is “stuck” together with other anchored parts to prevent them from falling apart in gameplay. Normally, simply building by stacking and placing parts on top of each other will only result in parts to sit loosely together, and as such can be manipulated through normal physics means like bumping into it, but anchoring will prevent this. Anchoring is useful when making objects that shouldn’t be easily moved around, such as houses and background props/scenery like trees.

The Anchored property requires two Boolean values called true and false.


Example:

game.Workspace.Part.Anchored = true

The class object in workspace is set.

BrickColor

[edit | edit source]

The BrickColor property requires hues or color names to be put in after "BrickColor.New"

Example:

workspace.part.BrickColor=BrickColor.new([Hue])