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

Script Wont Work After Player Dies What am I Doing Wrong?

Asked by 4 years ago
game.Players.PlayerAdded:connect(function(plr)
 plr.CharacterAdded:connect(function(char)
    if char.Humanoid.Health < 1 then
        plr.data.tp.Value = 0
    end
end)
end)

2 answers

Log in to vote
0
Answered by
ghxstlvty 133
4 years ago

Greetings, thank you for your post on Scripting Helpers.

Problem:

Your script is probably located in the incorrect place, if it is in StarterPlayer, you should move it to StarterCharacter. In StarterPlayer is will only run when you join.

How to solve:

Put the script in StarterCharacter.

Hope this works, -ecoszns

0
That is Server Script, I guess... Because why he use PlayerAdded event to get Player instance when he can use LocalPlayer(Which is can only work for LocalScript). Block_manvn 395 — 4y
0
I would of put it in ServerScriptService. Geobloxia 251 — 4y
Ad
Log in to vote
0
Answered by
Geobloxia 251 Moderation Voter
4 years ago

I see what the problem is. After the CharacterAdded function, add a wait(2) as a cooldown for the character and its children to load in. Like this:

game.Players.PlayerAdded:connect(function(plr)
 plr.CharacterAdded:connect(function(char)
    wait(2) -- cooldown
    if char.Humanoid.Health < 1 then
        plr.data.tp.Value = 0
    end
end)
end)

This error happens many times. You can't detect the health of the humanoid if it hasn't loaded in yet.

Answer this question