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: Coroutine question

Previous Thread :: Next Thread 
mamaguy is not online. 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
CeaselessSoul is not online. CeaselessSoul
Joined: 03 Jul 2012
Total Posts: 7506
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 is not online. 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
ElectricBlazeAlt is not online. ElectricBlazeAlt
Joined: 17 Aug 2012
Total Posts: 3535
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 is not online. 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
ElectricBlazeAlt is not online. ElectricBlazeAlt
Joined: 17 Aug 2012
Total Posts: 3535
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 is not online. 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 is not online. 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
ElectricBlazeAlt is not online. ElectricBlazeAlt
Joined: 17 Aug 2012
Total Posts: 3535
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 is not online. 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
ElectricBlazeAlt is not online. ElectricBlazeAlt
Joined: 17 Aug 2012
Total Posts: 3535
30 Sep 2012 12:12 AM
so much simpler

:P
Report Abuse
mamaguy is not online. 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 is not online. 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 is not online. 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 is not online. 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 is not online. mamaguy
Joined: 07 Oct 2010
Total Posts: 7073
30 Sep 2012 09:51 AM
Nvm, DP doesn't work :(
Report Abuse
mamaguy is not online. mamaguy
Joined: 07 Oct 2010
Total Posts: 7073
30 Sep 2012 01:31 PM
bump ples q.q
Report Abuse
mamaguy is not online. mamaguy
Joined: 07 Oct 2010
Total Posts: 7073
30 Sep 2012 01:52 PM
bump
Report Abuse
blackboy167thst is not online. blackboy167thst
Joined: 22 Jul 2011
Total Posts: 2468
30 Sep 2012 01:53 PM
Hai c: Me no help cuz me lazy :'3 *Free post* >:D
Report Abuse
ElectricBlazeAlt is not online. ElectricBlazeAlt
Joined: 17 Aug 2012
Total Posts: 3535
07 Nov 2012 04:33 PM
lol

http://wiki.roblox.com/index.php/User:ElectricBlaze
Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
07 Nov 2012 04:36 PM
None of that needs coroutines...
Report Abuse
Raphael7 is not online. 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
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