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

How do I select something with a "space"?

Asked by
epoke466 100
3 years ago

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?

0
Use square brackets instead of curly ones. radiant_Light203 1166 — 3y

2 answers

Log in to vote
1
Answered by
commag 228 Moderation Voter
3 years ago

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.

Ad
Log in to vote
0
Answered by
sayer80 457 Moderation Voter
3 years ago

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)

Answer this question