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

How to do spaces when finding things in character?

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 comment

1

For the record, this type of question has been asked several times.

1 answer

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)

7 comments

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.

0

I agree wih Lord. Hes just telling the questioner how to make his script better.

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.

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. :)

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. :)

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

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. :)

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