generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Out of Curiosity... [leaderstats/anon. coroutine]

Previous Thread :: Next Thread 
NewbControl114 is not online. NewbControl114
Joined: 09 May 2009
Total Posts: 10303
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 is not online. 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
NewbControl114 is not online. NewbControl114
Joined: 09 May 2009
Total Posts: 10303
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
NewbControl114 is not online. NewbControl114
Joined: 09 May 2009
Total Posts: 10303
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 is not online. 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
NewbControl114 is not online. NewbControl114
Joined: 09 May 2009
Total Posts: 10303
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 is not online. 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
NewbControl114 is not online. NewbControl114
Joined: 09 May 2009
Total Posts: 10303
20 Mar 2014 01:43 AM
I don't want seconds to reset. I want them to pause until respawn.
Report Abuse
frost209 is not online. 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 is not online. 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 is not online. 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
NewbControl114 is not online. NewbControl114
Joined: 09 May 2009
Total Posts: 10303
20 Mar 2014 01:48 AM
Alrighty.

Thanks.

Report Abuse
NewbControl114 is not online. NewbControl114
Joined: 09 May 2009
Total Posts: 10303
20 Mar 2014 01:50 AM
Oh, wow, I see what I did.

I'm so stupid.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image