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

Script is not removing body parts properly, need help please ?

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 ?

3 comments

0

change :children() to :GetChildren()

0

forgot to mention, make sure to close your for loop: for i, v in pairs(character:GetChildren()) do -[[ Code ]] end

0

try to avoid workspace:WaitForChild(player.Name) cause, what if a guy named "Part" joins the game and you have a part named "Part" lmao

2 answers

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

5 comments

0

you forgot to mention ":connect is deprecated"

0

i hasn't worked

0

are there any errors or warnings

0

no

0

tr adding wait(3) after the characteradded and see if it works. if it does, you can lower the wait time

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)

4 comments

0

nope, it's still not working !

0

If that isn't working have you tried putting your code in a serverscript? Your game may be FE and changes made with a local script won't be visible to the server.

0

the other question is are you using R15 or the other one

0

i use r15

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