mamaguy
|
  |
| Joined: 07 Oct 2010 |
| Total Posts: 7073 |
|
|
| 29 Sep 2012 11:44 PM |
Sorry for double post, XP I was wondering if using coroutines you could imitate something like: while true do points = points + 1 end in one script, and that script would have a playerAdded event also :P Thanks in advance |
|
|
| Report Abuse |
|
|
|
| 29 Sep 2012 11:44 PM |
I do that, yes.
http://www.roblox.com/CeaselessSouls-Admin-Commands-Gui-based-item?id=92856199 -- Take one and enjoy! Read the description, has a lot of information. |
|
|
| Report Abuse |
|
|
mamaguy
|
  |
| Joined: 07 Oct 2010 |
| Total Posts: 7073 |
|
|
| 29 Sep 2012 11:48 PM |
So would this work for multiple users: game.Players.PlayerAdded:connect(function (plr) ldr = Instance.new("IntValue", plr) ldr.Name = "leaderstats" points = Instance.new("IntValue", ldr) points.Name = "Points" if plr.DataReady and plr:LoadNumber("Points") then points.Value = plr:LoadNumber("Points") end local thing = coroutine.resume(coroutine.create(function() while wait(60) do points.Value = points.Value + 1 end end)) end)
|
|
|
| Report Abuse |
|
|
|
| 29 Sep 2012 11:50 PM |
| Yeah, but you don't even need to use a coroutine in this situation. The while loop is attributed to each player's leaderstat, so you can just include the while loop in the main thread. |
|
|
| Report Abuse |
|
|
mamaguy
|
  |
| Joined: 07 Oct 2010 |
| Total Posts: 7073 |
|
|
| 29 Sep 2012 11:53 PM |
@electric, Well, I did it for two reasons, 1. I want to learn how to effectively use coroutines :P 2. I tried using while wait(60) do without coroutines and it only did it for the first player to enter the game, because it will run in an infinite loop, never ending that PlayerAdded event, and idk it just doesn't work q.q |
|
|
| Report Abuse |
|
|
|
| 29 Sep 2012 11:56 PM |
Actually, it MAY need a coroutine... I can't test it right now because i can't install ROBLOX on this laptop.
But if you want to effectively learn how to use coroutines, try to do something that DEFINITELY needs coroutines. My suggestion: try to make it so that a TextLabel that every player has changes text and then waits a certain amount of time at the same time.
So, instead of one player's being changed, wait 5 seconds, the other changs, wait 5 seconds, the other changes, wait 5 seconds, etc., they all change text at the same time and they all wait 5 seconds at the same time. |
|
|
| Report Abuse |
|
|
mamaguy
|
  |
| Joined: 07 Oct 2010 |
| Total Posts: 7073 |
|
|
| 29 Sep 2012 11:58 PM |
Okay, I'll try that in the morning :P Right now I'm gonna go to sleep soon, and get tea with honey for my sore throat :D |
|
|
| Report Abuse |
|
|
mamaguy
|
  |
| Joined: 07 Oct 2010 |
| Total Posts: 7073 |
|
|
| 30 Sep 2012 12:05 AM |
I have a problem ;-; It works fine with 1 player, then when the second player comes, it puts the coroutine that the first player was using into the second player, so the second player gets 2 points every 1 second, and player 1 gets 0 every second same thing for 3rd, 4th, and 5th Any solutions? :/ |
|
|
| Report Abuse |
|
|
|
| 30 Sep 2012 12:09 AM |
game.Players.PlayerAdded:connect(function (plr) ldr = Instance.new("IntValue", plr) ldr.Name = "leaderstats" points = Instance.new("IntValue", ldr) points.Name = "Points" if plr.DataReady and plr:LoadNumber("Points") then points.Value = plr:LoadNumber("Points") end end)
while wait(60) do for k,v in pairs(game.Players:GetPlayers()) do v.leaderstats.Points.Value = v.leaderstats.Points.Value + 1 end end |
|
|
| Report Abuse |
|
|
mamaguy
|
  |
| Joined: 07 Oct 2010 |
| Total Posts: 7073 |
|
|
| 30 Sep 2012 12:12 AM |
Well look at u making it not use coroutines ;-;
|
|
|
| Report Abuse |
|
|
| |
|
mamaguy
|
  |
| Joined: 07 Oct 2010 |
| Total Posts: 7073 |
|
|
| 30 Sep 2012 12:17 AM |
Now, would this work: game.Players.PlayerAdded:connect(function (plr) ldr = Instance.new("IntValue", plr) ldr.Name = "leaderstats" points = Instance.new("IntValue", ldr) points.Name = "Points" if plr.DataReady and plr:LoadNumber("Points") then points.Value = plr:LoadNumber("Points") end points.Changed:connect(function(val) if val == "Value" then plr:SaveNumber("Points", points.Value) end end) end)
while wait(60) do for k,v in pairs(game.Players:GetPlayers()) do v.leaderstats.Points.Value = v.leaderstats.Points.Value + 1 end end
Also, to tired to do it now, but this would add it to every player, so if a player was in for 1 second, it would document it was 1 minute, so tomorrow, my goal is to use coroutines to set individual while wait(60) do statements for each player (without using scripts that I clone into the player) Last post of the night, cuz im sick, so yea |
|
|
| Report Abuse |
|
|
mamaguy
|
  |
| Joined: 07 Oct 2010 |
| Total Posts: 7073 |
|
|
| 30 Sep 2012 09:42 AM |
game.Players.PlayerAdded:connect(function (plr) ldr = Instance.new("IntValue", plr) ldr.Name = "leaderstats" points = Instance.new("IntValue", ldr) points.Name = "Points" if plr.DataReady and plr:LoadNumber("Points") then points.Value = plr:LoadNumber("Points") end points.Changed:connect(function(val) if val == "Value" then plr:SaveNumber("Points", points.Value) end local co = coroutine.wrap(function arg(player) while wait(1) do player.leaderstats.Points.Value = player.leaderstats.Points.Value + 1 end end) co(plr) end)
? :/
|
|
|
| Report Abuse |
|
|
mamaguy
|
  |
| Joined: 07 Oct 2010 |
| Total Posts: 7073 |
|
|
| 30 Sep 2012 09:47 AM |
I meant this: game.Players.PlayerAdded:connect(function (plr) ldr = Instance.new("IntValue", plr) ldr.Name = "leaderstats" points = Instance.new("IntValue", ldr) points.Name = "Points" if plr.DataReady and plr:LoadNumber("Points") then points.Value = plr:LoadNumber("Points") end points.Changed:connect(function(val) if val == "Value" then plr:SaveNumber("Points", points.Value) end end) local co = coroutine.wrap(function arg(player) while wait(1) do player.leaderstats.Points.Value = player.leaderstats.Points.Value + 1 end end) co(plr) end) |
|
|
| Report Abuse |
|
|
mamaguy
|
  |
| Joined: 07 Oct 2010 |
| Total Posts: 7073 |
|
|
| 30 Sep 2012 09:50 AM |
I actually meant (Final 1) this: game.Players.PlayerAdded:connect(function (plr) ldr = Instance.new("IntValue", plr) ldr.Name = "leaderstats" points = Instance.new("IntValue", ldr) points.Name = "Points" if plr.DataReady and plr:LoadNumber("Points") then points.Value = plr:LoadNumber("Points") end points.Changed:connect(function(val) if val == "Value" then plr:SaveNumber("Points", points.Value) end end) local co = coroutine.wrap(function (player) while wait(1) do player.leaderstats.Points.Value = player.leaderstats.Points.Value + 1 end end) co(plr) end) And it works, thanks for the help <---Not sarcasm |
|
|
| Report Abuse |
|
|
mamaguy
|
  |
| Joined: 07 Oct 2010 |
| Total Posts: 7073 |
|
| |
|
mamaguy
|
  |
| Joined: 07 Oct 2010 |
| Total Posts: 7073 |
|
| |
|
mamaguy
|
  |
| Joined: 07 Oct 2010 |
| Total Posts: 7073 |
|
| |
|
|
| 30 Sep 2012 01:53 PM |
| Hai c: Me no help cuz me lazy :'3 *Free post* >:D |
|
|
| Report Abuse |
|
|
|
| 07 Nov 2012 04:33 PM |
lol
http://wiki.roblox.com/index.php/User:ElectricBlaze |
|
|
| Report Abuse |
|
|
|
| 07 Nov 2012 04:36 PM |
| None of that needs coroutines... |
|
|
| Report Abuse |
|
|
Raphael7
|
  |
| Joined: 03 Dec 2008 |
| Total Posts: 2479 |
|
|
| 07 Nov 2012 04:44 PM |
| Coroutine isn't needed in this case, if you were to make game matches and make sure to sync every players with the change of any gui message. Then that would be necessary. |
|
|
| Report Abuse |
|
|