I am a beginning scripter and I am working on this leader board script, and I want it to reset the TimeAlive value to zero every time a person dies, but also convert that number into XP by dividing it by ten. When I test the script on the server, the TimeAlive value continues to go up, even after death, and it never resets or converts to xp. I tried a debounce also, which is the alive variable, but that didn't work either. I am kind of stuck, so please help!
--script by Legobrain9275--
local alive = true
game.Players.PlayerAdded:connect(function(player)
stats = Instance.new("IntValue", player)
stats.Name = "leaderstats"
timealive = Instance.new("IntValue", stats)
timealive.Name = "TimeAlive"
xp = Instance.new("IntValue", stats)
xp.Name = "XP"
level = Instance.new("IntValue", stats)
level.Name = "Level"
while alive == true do
wait(1)
player.leaderstats.TimeAlive.Value = player.leaderstats.TimeAlive.Value + 1
end
game.Players.PlayerAdded:connect(function(b)
b.Character:WaitForChild("Humanoid").Died:connect(function()
alive = false
b.Character:GetPlayerFromCharacter(c)
c.leaderstats.XP.Value = (c.leaderstats.XP.Value + (c.leaderstats.TimeAlive.Value/10))
c.leaderstats.TimeAlive.Value = 0
alive = true
end)
end)
if player.leaderstats.XP.Value >= 1000 then
player.leaderstats.Level.Value = player.leaderstats.Level.Value + 1
player.leaderstats.XP.Value = 0
end
end)

1 comment
Thank you so much!