|
| 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 |
|
|
|
| 20 Jun 2014 06:03 PM |
| Anyone good with coroutines? |
|
|
| Report Abuse |
|
|
| |
|
| |
|
| |
|
|
| 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
|
  |
| Joined: 01 Dec 2009 |
| Total Posts: 392 |
|
|
| 20 Jun 2014 06:50 PM |
| ^ Nobody knows what Coroutines are. |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
|
| 20 Jun 2014 06:54 PM |
| And if you wanted to run that coroutine, you simply call `coroutine.resume(thread1)`. |
|
|
| Report Abuse |
|
|
|
| 20 Jun 2014 06:59 PM |
| Now the script does not work...plus I already tried the wiki. My script is suspended. |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
| |
|
|
| 20 Jun 2014 07:48 PM |
| I don't get this...I came to ask for help! |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
|
| 20 Jun 2014 07:51 PM |
| Their Is no output. It just sits their. |
|
|
| Report Abuse |
|
|
|
| 20 Jun 2014 07:55 PM |
| Ok, the second part of the post? Where are the variables updated? |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
| |
|
| |
|
|
| 20 Jun 2014 08:03 PM |
| Yeah, I saw you defined it, but you never updated it..? |
|
|
| Report Abuse |
|
|
| |
|
|
| 20 Jun 2014 08:03 PM |
I don't think, anyway.
Your code is quite long. |
|
|
| Report Abuse |
|
|
|
| 20 Jun 2014 08:06 PM |
| So, this script Is never going to work? |
|
|
| Report Abuse |
|
|
|
| 20 Jun 2014 08:07 PM |
No, just say time = tick() in the while-do loop.
Do you even need that coroutine? |
|
|
| Report Abuse |
|
|