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

Why does this not remove the arms and legs of the player.Character?

Asked by 9 years ago
function modifyPlayer( player )
    player.Character:WaitForChild("Humanoid")
    repeat wait() until player.Character.Humanoid ~= nil
    player.Character.Head.Transparency = 1
    player.Character["Left Leg"]:Destroy()
    player.Character["Right Leg"]:Destroy()
    player.Character.["Right Arm"]:Destroy()
    player.Character.["Left Arm"]:Destroy()
end

function newPlayer( player )
    repeat
        wait()
    until player.Character
    modifyPlayer( player )
end

game.Players.PlayerAdded:connect(newPlayer)

1 answer

Log in to vote
0
Answered by
Thetacah 712 Moderation Voter
9 years ago

I suggest not making two functions when you can merge them into one, two is completely inefficient and ridiculous. That's the first step I'd do.

Secondly, why are you waiting for the humanoid, then making sure it's not nil? Why do we care if the humanoid is there? We know its a legitimate player if the playeraddded event runs!

Humanoid is completely useless in this function, don't just take bits and pieces of code you see others using to make your code look shiny!

player.Character.["Left Arm"]:Destroy() You can't use a dot if you're going to use square brackets. Chose what you're going to use rather that's FindFirstChild, WaitForChild or square brackets.

After I merged the scripts and corrected a few things, I was left with this fully working script.

NOTE: If you expect the humanoid to be in the character(I assume by you using repeat wait() until) why not use WaitForChild? I also made it a variable if you need the humanoid later in this script. The only reason I waited for the humanoid in this script is for future references. Keep in mind that in some cases, the object you're waiting for may not be there and the script will be stuck at the wait line. It's all good in this case, though.

Have a great day,

Cheers

function modifyPlayer(player)
    repeat wait() until player.Character    
        player.Character.Head.Transparency = 1
    local hum =  player.Character:WaitForChild("Humanoid")
      player.Character["Left Leg"]:Destroy()
      player.Character["Right Leg"]:Destroy()
      player.Character["Right Arm"]:Destroy()
     player.Character["Left Arm"]:Destroy()
end
game.Players.PlayerAdded:connect(modifyPlayer)

Ad

Answer this question