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

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

Asked by 5 years ago

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 ?

0
change :children() to :GetChildren() DragonSkyye 517 — 5y
0
forgot to mention, make sure to close your for loop: for i, v in pairs(character:GetChildren()) do -[[ Code ]] end DragonSkyye 517 — 5y
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 greatneil80 2647 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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

0
you forgot to mention ":connect is deprecated" yHasteeD 1819 — 5y
0
i hasn't worked Cioss_Team 14 — 5y
0
are there any errors or warnings Gey4Jesus69 2705 — 5y
0
no Cioss_Team 14 — 5y
0
tr adding wait(3) after the characteradded and see if it works. if it does, you can lower the wait time Gey4Jesus69 2705 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

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)
0
nope, it's still not working ! Cioss_Team 14 — 5y
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. Shadowthaumaturge 97 — 5y
0
the other question is are you using R15 or the other one DragonSkyye 517 — 5y
0
i use r15 Cioss_Team 14 — 5y

Answer this question