Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Won't subtract value from leaderstats?

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.)

1 comment

0

Did you set up the leaderstats, or the lives value yet? When you set them up, were they capitalized?

1 answer

✓ Accepted answer

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.