Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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?

1 comment

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 

1 answer

✓ Accepted answer

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.