Here's the script:
function onPlayerEntered(newPlayer)
if newPlayer.Character.Humanoid.Health == 0 then newPlayer.leaderstats.Lives.Value = newPlayer.leaderstats.Lives.Value - 1 end end
game.Players.PlayerAdded:connect(onPlayerEntered)
But then if I do
function onPlayerEntered(newPlayer)
wait(1) newPlayer.leaderstats.Lives.Value = 5 end
game.Players.PlayerAdded:connect(onPlayerEntered)
to test if my function is working correctly, it does. But then my actual script won't work when I kill my player. Am I missing something here?
(Sorry if this is a stupid mistake or bad question, i'm new to lua.)
Well, I think you want it to subtract a leaderstat when the player dies? In that case you should use,
game.Players.PlayerAdded:connect(function(p) p.Character.Humanoid.Died:connect(function() p.leaderstats.Lives.Value = p.leaderstats.Lives.Value - 1--Change to the name of the leaderstat and how many you want to add/subtract end) end)
Hope this helps, don't forget to accept the answer if it worked! It gives us both rep.