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

How do I select something with a "space"?

So I'm making a tool that when equipped it makes the left leg of a player transparent.

Here's the original script:

script.Parent.Equipped:Connect(function()
	wait(0.5)
	script.Parent.Parent.LeftLeg.Transparency = 1
end)

There was an error so I went into my game explorer and found out that my character didn't have a "leftLeg" it had a "Left Leg"

So I changed the script to this:

script.Parent.Equipped:Connect(function()
	wait(0.5)
	script.Parent.Parent{"Left Leg"}.Transparency = 1
--         The error is here ^ I think?
end)

But the leg still isn't becoming transparent, can someone please help me?

1 comment

0

Use square brackets instead of curly ones.

2 answers

✓ Accepted answer

script.Parent.Parent['Left Leg']

Here's the reason why this is the case if you're interested

The list of an object's children can be treated as a dictionary, or associative array, or whatever you want to call it. We avoid this where possible but with Instances where the name includes a space, there is no avoiding it. For example, in the code below, I have a disctionary and I reference the second value.

myArray = {'partOne' = myPart.childOne, 'partTwo' = myPart.childTwo}
childTwo = myArray['partTwo']

This is similar to how roblox views an Instance's children, with the key value pair being the child's name and the child's instance. Therefore, you can reference an Instance's children the same way you would reference values in a dictionary. I hope this was helpful to you.

I prefer to use this on "Space"

script.Parent.Equipped:Connect(function()
    wait(0.5)
    script.Parent.Parent:FindFirstChild("Left Leg").Transparency = 1
--         The error is here ^ I think?
end)

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