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

How to do spaces when finding things in character?

Asked by 9 years ago

For example,

function PlayerJoined(p) 
game.Workspace.p.Character.Right Leg:Destroy()
end
game.Players.PlayerAdded:connect(PlayerJoined)

This won't work, I think because of the space between Right and Leg. Here is really what I'm asking :/

game.Workspace.p.Character.Right Leg:Destroy()
1
For the record, this type of question has been asked several times. alphawolvess 1784 — 9y

1 answer

Log in to vote
2
Answered by
iaz3 190
9 years ago

Use brackets to access a name directly that has spaces, shown below.

game.Workspace.p.Character["Right Leg"]:Destroy()

Also, you script has several minor errors.

Your script runs when the player is added, and it runs PlayerJoined. When this happens, it passes the player itself to your function.

"p" in your function is the player, so you do not need to go game.Workspace.p.Character Also, players in a game are stored in game.Players the characters are in Workspace

Your code should then be as follows

function PlayerJoined(p) 
    p.Character["Right Leg"]:Destroy()
end
game.Players.PlayerAdded:connect(PlayerJoined)

I would also add a check to make sure the character exists, just in case.

function PlayerJoined(p) 
    repeat wait() until p.Character
    p.Character["Right Leg"]:Destroy()
end
game.Players.PlayerAdded:connect(PlayerJoined)

0
Or use FindFirstChild. This would be better because you can use an if statement to see if it's not nil or it's true/exists so the script doesn't error. This isn't the best way to do it. EzraNehemiah_TF2 3552 — 9y
0
I agree wih Lord. Hes just telling the questioner how to make his script better. Operation_Meme 890 — 9y
0
Also, on this site, you need to add an explanation on how it works. The reason why the site is strict like this is because if you give one bit of incorrect information, you get like 6 thumbs down. It's just Scripting Helpers. EzraNehemiah_TF2 3552 — 9y
0
I think Lord was asking; 'What if the Leg was not existant within the character at time of execution?' Because, this bug is still on ROBLOX, and, as the code stands, it will error if the Leg is not existant on execution, just giving ya a heads up. :) TheeDeathCaster 2368 — 9y
View all comments (3 more)
0
There is a currently bug in ROBLOX, as I have explained, where an Instance will NOT be existant at time of the execution of a chunk of code, also, there's no reason to be hostile. :P What we're trying to say is; If the leg is not existant for a Player that joins, the code will break. :) TheeDeathCaster 2368 — 9y
0
There is no reason to be hostile. :P All we're doing is telling you something you may have missed. :) Also, 'The Character is more likely to be non existant', true, but, that doesn't count for the Legs? XP TheeDeathCaster 2368 — 9y
0
Why not call the 'WaitForChild' method, then call the code with the brackets? :P The 'WaitForChild' method will pause, or yield, the chunk until a Child with a matching name of the Argument is existant. :) TheeDeathCaster 2368 — 9y
Ad

Answer this question