|
| 20 Mar 2014 01:22 AM |
game.Players.PlayerAdded:connect(function(player)
local leaderstats = Instance.new("IntValue", player) leaderstats.Name = ("leaderstats") local seconds = Instance.new("IntValue", leaderstats) seconds.Name = ("Time (sec)") coroutine.resume(coroutine.create(function() while wait(1) and player.Character.Humanoid.Health > 0 do seconds.Value = seconds.Value + 1 end end)) while true do if player.Character ~= nil then break end wait(5) end
end)
So, yay, used anonymous functions and successfully coded my first anonymous coroutine (woo). Problem is, this leaderstat stops counting (it is supposed to count seconds alive, stop when dead, and resume when alive again) once I've respawned after resetting.
My guess and assumption is that because the coroutine's in a PlayerAdded function, it does not resume indefinitely and stops once said person is dead.
Just wondering, was that a correct assumption, or did I make another error?
Thaaanks.
No errors, by the way... (First try, like a boss!) |
|
|
| Report Abuse |
|
|
Absurdism
|
  |
| Joined: 18 Jul 2013 |
| Total Posts: 2568 |
|
|
| 20 Mar 2014 01:24 AM |
| No. When you attach a CharacterAdded event to a player inside of the PlayerAdded event, does it simply fade away? |
|
|
| Report Abuse |
|
|
|
| 20 Mar 2014 01:25 AM |
| I don't quite follow. Is there a different effect between using PlayerAdded and CharacterAdded to detect new players? |
|
|
| Report Abuse |
|
|
|
| 20 Mar 2014 01:25 AM |
| I don't quite follow. Is there a different effect between using PlayerAdded and CharacterAdded to detect new players? |
|
|
| Report Abuse |
|
|
Absurdism
|
  |
| Joined: 18 Jul 2013 |
| Total Posts: 2568 |
|
|
| 20 Mar 2014 01:26 AM |
PlayerAdded triggers when a user enters the game. CharacterAdded fires when the player spawns/respawns. In other words, no, the coroutine continues. |
|
|
| Report Abuse |
|
|
|
| 20 Mar 2014 01:38 AM |
| The seconds do not continue adding after the respawn. Will it change if I make it CharacterAdded? |
|
|
| Report Abuse |
|
|
wazap
|
  |
| Joined: 29 Jun 2007 |
| Total Posts: 23234 |
|
|
| 20 Mar 2014 01:42 AM |
game.Players.PlayerAdded:connect(function(player)
local leaderstats = Instance.new("IntValue", player) leaderstats.Name = ("leaderstats")
local seconds = Instance.new("IntValue", leaderstats) seconds.Name = ("Time (sec)")
coroutine.resume(coroutine.create(function() while wait(1) do seconds.Value = seconds.Value + 1 if player.Character.Humanoid.Health == 0 then seconds.Value = 0 repeat wait() until player.Character and player.Character.Humanoid.Health > 0 end end end))
while true do if player.Character ~= nil then break end wait(5) end
end) |
|
|
| Report Abuse |
|
|
|
| 20 Mar 2014 01:43 AM |
| I don't want seconds to reset. I want them to pause until respawn. |
|
|
| Report Abuse |
|
|
frost209
|
  |
| Joined: 31 Aug 2008 |
| Total Posts: 90 |
|
|
| 20 Mar 2014 01:43 AM |
coroutine.resume(coroutine.create(function() while wait(1) and player.Character.Humanoid.Health > 0 do -- This is reason why it stops because once the player's health is 0 the loop will stop forever. seconds.Value = seconds.Value + 1 end end)) |
|
|
| Report Abuse |
|
|
wazap
|
  |
| Joined: 29 Jun 2007 |
| Total Posts: 23234 |
|
|
| 20 Mar 2014 01:43 AM |
Then take out the seconds.Value = 0 ._.
OD me. |
|
|
| Report Abuse |
|
|
frost209
|
  |
| Joined: 31 Aug 2008 |
| Total Posts: 90 |
|
|
| 20 Mar 2014 01:47 AM |
| i was way behind on the page, when i had page open there was only like two comments then i whent afk and came back to respond. Diddnt notice there was more comments XD. |
|
|
| Report Abuse |
|
|
| |
|
|
| 20 Mar 2014 01:50 AM |
Oh, wow, I see what I did.
I'm so stupid. |
|
|
| Report Abuse |
|
|