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

Won't subtract value from leaderstats?

Asked by
MaxxHD 10
8 years ago

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

0
Did you set up the leaderstats, or the lives value yet? When you set them up, were they capitalized? Azmidium 388 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

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.

Ad

Answer this question