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

CharacterAdded code messes up when interacting with Character?

Asked by 3 years ago
game.Players.PlayerAdded:Connect(function(Player)
    local Char = Player.Character or Player.CharacterAdded:Wait()
    wait(3)
    Char:WaitForChild("Humanoid").Health = 0
end)


game.Players.PlayerAdded:Connect(function(Player)
    Player.CharacterAdded:Connect(function(Character)
        Character:WaitForChild("Humanoid").Health = 0
    end)
end)

This is basically the same code

I need the player to die so that they respawn as my custom character script

and yes I have tried manually setting the custom character when they join the game

and it still does the same thing

I have tried to do LoadCharacter everything

The code does run but it does not kill the player

I have also tried

game.Players.PlayerAdded:Connect(function(Player)
    Player.CharacterAdded:Connect(function(Character)
        Character:SetPrimaryPartCFrame(CFrame.new(0,99999,0))
    end)
end)

To see if my code was working but from what I see

Anything relating to the character does not work with characterAdded

when they first join in the game

you need to place a wait

does anyone know a solution to this that does not require something along the lines of doing

wait(5)

Cause this is completely unreliable

0
Killing the player when they spawn seems like a bandaid fix. Try setting Players.CharacterAutoLoads to false and Player:LoadCharacter(). jundell 106 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago

I’d recommend using

repeat task.wait() until plr.Character

It would check if Character is a children of player. (you would need to put this inside CharacterAdded)

Ad

Answer this question