Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How do you grab a data value from a table so you can reference it as a property, not a child?

Asked by 5 years ago
Edited 5 years ago

I am trying to make my avatar's body parts change into random colors, but then it keeps saying, "x is not a valid member of BodyColors," but c has information in it. I used this script:

local c = {"HeadColor", "LeftArmColor", "LeftLegColor", "RightArmColor", "RightLegColor", "TorsoColor"} local x = c[math.random(1,6)]

function a() local snak = game.Workspace:WaitForChild("snaks308070") snak:WaitForChild("Body Colors", 3).x = BrickColor.Random() end

while true do wait() a() end

Any help?

0
please specify what is "Body Colors" and if the "c" mentioned in the question is the array in the script, if not, specify what "c" is as well  theking48989987 2147 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

Similar to

Parent['Child_Name_String']

These can also be used to locate properties.

local partn = Instance.new('Part',workspace)
partn.Name = 'Part_ex'
local ex_name = partn['Name']
print(ex_name ) -- prints Part_ex.

Mainly because properties are like children, as such, they have similar features like this.

Ad

Answer this question