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

Script not killing on PlayerAdded?

Asked by 9 years ago

Script:

game.Players.PlayerAdded:connect(function(player)
    player.Character.Head:remove()
end)

I just want the player to die when they first join and I am getting this error: Workspace.PlayerAdded:3: attempt to index field 'Character' (a nil value)

Please help! Thanks.

2 answers

Log in to vote
0
Answered by
Mokiros 135
9 years ago

Your script running before player character even spawns. You must add repeat loop into first function, and then wait until character head loads. Or you can wait for Humanoid and set health to 0 (alternate killing way)

game.Players.PlayerAdded:connect(function(player)
    repeat wait() until player.Character
    char = player.Character
    char:WaitForChild("Head"):Destroy() --Wait until head creates, and then destroy it.
end)
Ad
Log in to vote
0
Answered by 5 years ago
script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        hit.Parent.Humanoid.Health = 0
    end
end)

Answer this question