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

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

Asked by 9 years ago

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

Log in to vote
1
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
9 years ago

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

0
It still does not work, the moeny was fine the deaths wern't working. BosswalrusTheCoder 88 — 9y
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. adark 5487 — 9y
0
It didn't work. BosswalrusTheCoder 88 — 9y
0
It also stops the Money from +1 BosswalrusTheCoder 88 — 9y
View all comments (3 more)
0
I recommend using a coroutine. Shawnyg 4330 — 9y
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) adark 5487 — 9y
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. BosswalrusTheCoder 88 — 9y
Ad
Log in to vote
0
Answered by
Lacryma 548 Moderation Voter
9 years ago

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.

Log in to vote
0
Answered by 9 years ago
-- 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!

Answer this question