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: Coroutines...?

Previous Thread :: Next Thread 
peoplemove12 is not online. peoplemove12
Joined: 11 Feb 2010
Total Posts: 1442
20 Jun 2014 05:49 PM
This works but the part where It is suppose to countdown just does not countdown.

THE PROBLEM:
coroutine.resume(coroutine.create(function()
while true do wait()
Seconds = Amount-(time-Orginal)
Minutes = Seconds/60
Timer.Text = "Next award: "..math.ceil(Minutes)
coroutine.status(coroutine.create)
end
end))

THE SCRIPT:
DataStore = Game:GetService("DataStoreService"):GetDataStore("Reward")
Amount = 120

Game.Players.PlayerAdded:connect(function(Player)
repeat wait(1) until Player:FindFirstChild("CashPLAYER")
repeat wait(1) until Player:FindFirstChild("LevelPLAYER")
local CashPLAYER = Player:FindFirstChild("CashPLAYER");
local LevelPLAYER = Player:FindFirstChild("LevelPLAYER");
local PlayerGui = Player:WaitForChild("PlayerGui"):WaitForChild("Menu");
local TextLabel = PlayerGui.TextLabel5
local Timer = PlayerGui.Level.TextLabel3
mod = Instance.new("BoolValue", Player)
mod.Name = "Award"
mod.Value = false
if DataStore:GetAsync(Player.Name) then
Orginal = DataStore:GetAsync(Player.Name)
time = math.floor(tick())
if time-Orginal > Amount then
CashPLAYER.Value = CashPLAYER.Value + 75
TextLabel.Visible = true
Player.Award.Value = true
wait(3)
TextLabel.Visible = false
end
else
time = tick()
DataStore:SetAsync(Player.Name, time)
CashPLAYER.Value = CashPLAYER.Value + 75
TextLabel.Visible = true
Player.Award.Value = true
wait(3)
TextLabel.Visible = false
end
coroutine.resume(coroutine.create(function()
while true do wait()
Seconds = Amount-(time-Orginal)
Minutes = Seconds/60
Timer.Text = "Next award: "..math.ceil(Minutes)
end
end))
end)

Game.Players.PlayerRemoving:connect(function(Player)
if Player.Award.Value == true then
time = math.floor(tick())
DataStore:SetAsync(Player.Name, time)
end
end)
Report Abuse
peoplemove12 is not online. peoplemove12
Joined: 11 Feb 2010
Total Posts: 1442
20 Jun 2014 06:03 PM
Anyone good with coroutines?
Report Abuse
peoplemove12 is not online. peoplemove12
Joined: 11 Feb 2010
Total Posts: 1442
20 Jun 2014 06:14 PM
Anyone? Please!
Report Abuse
peoplemove12 is not online. peoplemove12
Joined: 11 Feb 2010
Total Posts: 1442
20 Jun 2014 06:25 PM
?
Report Abuse
peoplemove12 is not online. peoplemove12
Joined: 11 Feb 2010
Total Posts: 1442
20 Jun 2014 06:36 PM
.
Report Abuse
BloodLitch101 is not online. BloodLitch101
Joined: 13 Jul 2011
Total Posts: 941
20 Jun 2014 06:47 PM
The actual scripters are offline. Most of these "helpers" don't even know what coroutine are.
Report Abuse
Cboehme is not online. Cboehme
Joined: 01 Dec 2009
Total Posts: 392
20 Jun 2014 06:50 PM
^ Nobody knows what Coroutines are.
Report Abuse
TheNewScripter is not online. TheNewScripter
Joined: 02 Mar 2010
Total Posts: 2432
20 Jun 2014 06:53 PM
^ I'm fully aware of what they are and how to use them, but the problem isn't with the coroutines. The problem is the actual code inside the coroutine.

Also, the line `coroutine.status(coroutine.create)` is probably why it's breaking. `coroutine.status` requires a thread (or a coroutine) to be passed as an argument, not a function. `coroutine.create` is a function inside the table `coroutine`, so that's probably why the error is happening. If you just want to know the status of the thread, you're going to need to have something like this:

    local thread1 = coroutine.create(function() --[[ all the code here ]] end)
    print(coroutine.status(thread1))
    
    coroutine.wrap(function()
        print(coroutine.status(thread1))
    end)()
Report Abuse
TheNewScripter is not online. TheNewScripter
Joined: 02 Mar 2010
Total Posts: 2432
20 Jun 2014 06:54 PM
And if you wanted to run that coroutine, you simply call `coroutine.resume(thread1)`.
Report Abuse
peoplemove12 is not online. peoplemove12
Joined: 11 Feb 2010
Total Posts: 1442
20 Jun 2014 06:59 PM
Now the script does not work...plus I already tried the wiki. My script is suspended.
Report Abuse
TheNewScripter is not online. TheNewScripter
Joined: 02 Mar 2010
Total Posts: 2432
20 Jun 2014 07:06 PM
Try moving the while loop to the end of the script. The only time you really ever need to use coroutine is when you have two while loops running, or if you want to handle errors in your code. Moving the while loop to the end of the script shouldn't have any negative impact.
Report Abuse
peoplemove12 is not online. peoplemove12
Joined: 11 Feb 2010
Total Posts: 1442
20 Jun 2014 07:13 PM
Can you help me with that please? Thank you for helping out, means a lot to me!
Report Abuse
peoplemove12 is not online. peoplemove12
Joined: 11 Feb 2010
Total Posts: 1442
20 Jun 2014 07:26 PM
Please?
Report Abuse
peoplemove12 is not online. peoplemove12
Joined: 11 Feb 2010
Total Posts: 1442
20 Jun 2014 07:48 PM
I don't get this...I came to ask for help!
Report Abuse
Notunknown99 is not online. Notunknown99
Joined: 05 Sep 2008
Total Posts: 25360
20 Jun 2014 07:50 PM
while true do wait()
Seconds = Amount-(time-Orginal)
Minutes = Seconds/60
Timer.Text = "Next award: "..math.ceil(Minutes)
end

Ok, is there any output?

And when are Amount, time and Original changed?
Report Abuse
peoplemove12 is not online. peoplemove12
Joined: 11 Feb 2010
Total Posts: 1442
20 Jun 2014 07:51 PM
Their Is no output. It just sits their.
Report Abuse
Notunknown99 is not online. Notunknown99
Joined: 05 Sep 2008
Total Posts: 25360
20 Jun 2014 07:55 PM
Ok, the second part of the post? Where are the variables updated?
Report Abuse
peoplemove12 is not online. peoplemove12
Joined: 11 Feb 2010
Total Posts: 1442
20 Jun 2014 07:57 PM
? This all works, It's just the loops does not. It shows like 180 seconds then freezes their but player receive their award.
Report Abuse
Notunknown99 is not online. Notunknown99
Joined: 05 Sep 2008
Total Posts: 25360
20 Jun 2014 07:58 PM
When is time changed?
Report Abuse
peoplemove12 is not online. peoplemove12
Joined: 11 Feb 2010
Total Posts: 1442
20 Jun 2014 08:01 PM
time = tick()
Report Abuse
Notunknown99 is not online. Notunknown99
Joined: 05 Sep 2008
Total Posts: 25360
20 Jun 2014 08:03 PM
Yeah, I saw you defined it, but you never updated it..?
Report Abuse
peoplemove12 is not online. peoplemove12
Joined: 11 Feb 2010
Total Posts: 1442
20 Jun 2014 08:03 PM
How shall I update it?
Report Abuse
Notunknown99 is not online. Notunknown99
Joined: 05 Sep 2008
Total Posts: 25360
20 Jun 2014 08:03 PM
I don't think, anyway.

Your code is quite long.
Report Abuse
peoplemove12 is not online. peoplemove12
Joined: 11 Feb 2010
Total Posts: 1442
20 Jun 2014 08:06 PM
So, this script Is never going to work?
Report Abuse
Notunknown99 is not online. Notunknown99
Joined: 05 Sep 2008
Total Posts: 25360
20 Jun 2014 08:07 PM
No, just say time = tick() in the while-do loop.

Do you even need that coroutine?
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