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

We are having problems with the deaths on the leaderboard not working, can you help?

This is a Cash, KO, WO leaderboard

-- Start leaderboard
game.Players.PlayerAdded:connect(function(player)
 
 -- Make leaderstats
 local leaderstats = Instance.new("IntValue", player)
 leaderstats.Name = "leaderstats"
 
 local money = Instance.new("IntValue", leaderstats)
 money.Name = "Cash"
 money.Value = 100
 
 local deaths = Instance.new("IntValue", leaderstats)
 deaths.Name = "Deaths"
 deaths.Value = 0
 
 local kills = Instance.new("IntValue", leaderstats)
 kills.Name = "Kills"
 kills.Value = 0
 
 
 
 -- Do stuff
 while true do
  money.Value = money.Value + 1
  wait(1)
 end
 
 player.Character:WaitForChild("Humanoid").Died:connect(function()
     deaths.Value = deaths.Value + 1
   end)
end)

3 answers

That while true do loop never exits, so the function beneath it is never reached and therefore never connected.

Just move the loop to the bottom of the function and you're fine. :P

7 comments

0

It still does not work, the moeny was fine the deaths wern't working.

0

That what this fixes. The functions that manages the deaths never connects because the loop is initiated before it. Move the loop to BELOW that function.

0

It didn't work.

0

It also stops the Money from +1

0

I recommend using a coroutine.

0

Are you putting the loop inside of the Humanoid.Died function, or below? It has to be below it, inside of the final end)

0

I put it isnide the final end), also I don't know how to script a coroutine I've been wanting to knwo what it is.

As stated by adark, you should use a coroutine.

-- Start leaderboard
game.Players.PlayerAdded:connect(function(player)

 -- Make leaderstats
 local leaderstats = Instance.new("IntValue", player)
 leaderstats.Name = "leaderstats"

 local money = Instance.new("IntValue", leaderstats)
 money.Name = "Cash"
 money.Value = 100

 local deaths = Instance.new("IntValue", leaderstats)
 deaths.Name = "Deaths"
 deaths.Value = 0

 local kills = Instance.new("IntValue", leaderstats)
 kills.Name = "Kills"
 kills.Value = 0



 -- Do stuff
coroutine.resume(coroutine.create(function()
 while true do
  money.Value = money.Value + 1
  wait(1)
 end
end))

 player.Character:WaitForChild("Humanoid").Died:connect(function()
     deaths.Value = deaths.Value + 1
   end)
end)

To learn more, read the wiki article: here.

-- Start leaderboard
game.Players.PlayerAdded:connect(function(player)

 -- Make leaderstats
 local leaderstats = Instance.new("IntValue", player)
 leaderstats.Name = "leaderstats"

 local money = Instance.new("IntValue", leaderstats)
 money.Name = "Cash"
 money.Value = 100

 local deaths = Instance.new("IntValue", leaderstats)
 deaths.Name = "Deaths"
 deaths.Value = 0

 local kills = Instance.new("IntValue", leaderstats)
 kills.Name = "Kills"
 kills.Value = 0



 -- Do stuff
 while true do
  money.Value = money.Value + 1
  wait(1)
 end

local deadnow = player.Character:WaitForChild("Humanoid").Health
     if deadnow == 0 then
     deaths.Value = deaths.Value + 1
   end)
end)

Get in contact with me click here!

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