So my script i supposed to remove the player's arm :
game:GetService("Players").PlayerAdded:connect(function(player) --Connects specified function when player joins. player.CharacterAdded:connect(function() --Connects specified function when player's character is loaded. local character = workspace:WaitForChild(player.Name) --We can now refer to the player's character as "character". for i,v in pairs(character:children()) do --Gets all of character's children. character:WaitForChild("LeftArm"):Destroy() --Destroys Left arms character:WaitForChild("RightArm"):Destroy() --Same but left end) end)
But it won't work, what is wrong ?
Your issue is that you never closed your for
loop with an end
. Additionally, your for
loop is completely unnecessary. Also, note that we don't need to check if the parts in question exist, because we're utilizing :WaitForChild()
. Thus, the script will yield if they don't.
game.Players.PlayerAdded:Connect(function(player) player.CharacterAdded:Connect(function(char) char:WaitForChild("LeftArm"):Destroy() char:WaitForChild("RightArm"):Destroy() end end)
:children()
was also deprecated in favor of :GetChildren()
.
Lets remake your code and explain through the process
Links to help you learn:
game.Players.PlayerAdded:Connect(function(Player) Player.CharacterAdded:Connect(function(Character) -- you forgot to add Character --[[local character = workspace:WaitForChild(player.Name)]] -- There is no need for this Character:WaitForChild("LeftArm"):Destroy() --Destroys LeftArm Character:WaitForChild("RightArm"):Destroy() -- Destroys RightArm -- You dont need a for loop to Destroy the LeftArm and the RightArm end) end)