|
| 18 Mar 2014 12:25 AM |
Hi,
I'd like for an event to take place that when a timer is finished counting from 10, a value in Workspace named 'GameV's value would be '2.' This is what I have so far...
GameV = script.Parent.Parent.GameV
function works() while true do script.Parent.Value = script.Parent.Value - 1 wait(1) end end
repeat works() until script.Parent.Value == 0 if script.Parent.Value == 0 then GameV.Value = 3 end |
|
|
| Report Abuse |
|
|
| |
|
wazap
|
  |
| Joined: 29 Jun 2007 |
| Total Posts: 23234 |
|
|
| 18 Mar 2014 12:40 AM |
GameV = script.Parent.Parent.GameV
function works() if script.Parent.Value == 0 then GameV.Value = 3 else script.Parent.Value = script.Parent.Value - 1 wait(1) end end
script.Parent.Changed:connect(function() works end)
|
|
|
| Report Abuse |
|
|
|
| 18 Mar 2014 12:41 AM |
| Are you getting any errors in the Output? If so, post them here. |
|
|
| Report Abuse |
|
|
|
| 18 Mar 2014 07:43 AM |
| I used the script @2 above and it said that it was unable to take place. |
|
|
| Report Abuse |
|
|
Clickest
|
  |
| Joined: 06 Aug 2013 |
| Total Posts: 6504 |
|
|
| 18 Mar 2014 08:14 AM |
You Don't Need To Capitalize The First Letter In Each Word.
-Clickest |
|
|
| Report Abuse |
|
|
|
| 18 Mar 2014 08:46 AM |
| So far, it counts down perfectly, but when it gets to 0, it goes to the negatives. |
|
|
| Report Abuse |
|
|
|
| 18 Mar 2014 09:01 AM |
I think I can see why.
You see, when you first called the function works(), you started a while true loop right?
However, that while true loop will go on forever and ever, since you didn't tell it where to stop, or stop it manually.
A way to do this would be to make an "if" statement that checks the value each time it loops. See like this:
function wait() while true do if script.Parent.Value ~= 0 then script.Parent.Value = script.Parent.Value - 1 else break() GameV.Value = 3 end end end
In this script, I removed the unnecessary repeat(the while loop already repeats the works() ), added the "if this equals zero then" inside works() and finally, used the break() function to stop the loop once it reaches 0. |
|
|
| Report Abuse |
|
|
|
| 18 Mar 2014 09:03 AM |
| Ahhhhhh. Ok. Thanks. I thought it might have to do with an 'until' state ment, but now I know. Thanks for walking me through it! |
|
|
| Report Abuse |
|
|
|
| 18 Mar 2014 09:03 AM |
| Wait, actually don't use break(), simply use break. Lol :P |
|
|
| Report Abuse |
|
|
|
| 18 Mar 2014 09:15 AM |
| Ok. Just curious, though, what's the difference? |
|
|
| Report Abuse |
|
|
|
| 18 Mar 2014 11:26 AM |
| break() was a mistake I made. There aren't supposed to be any parenthesis. |
|
|
| Report Abuse |
|
|
|
| 18 Mar 2014 03:07 PM |
| I took out the parentheses on 'break()' and now, the line where it says "GameV.Value = 3" is underlined in red and it says 'end expected near GameV.' I tried adding more ends and it didn't work. |
|
|
| Report Abuse |
|
|
| |
|
| |
|
| |
|
|
| 18 Mar 2014 06:21 PM |
| There has got to be some way to do this... |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 18 Mar 2014 06:24 PM |
local timer = script.Parent.Parent.GameV
while true do while timer.Value > 0 do timer.Value = timer.Value - 1 wait(1) end --anything under here will run when the timer is done timer.Value = 3 end
is this what you want? |
|
|
| Report Abuse |
|
|
|
| 18 Mar 2014 06:26 PM |
num = 60 repeat num = num - 1 until num == 0 --Insert code here This will countown form 60 |
|
|
| Report Abuse |
|
|
|
| 18 Mar 2014 06:26 PM |
num = 60 repeat num = num - 1 wait(1) until num == 0 |
|
|
| Report Abuse |
|
|
|
| 18 Mar 2014 06:35 PM |
| Thank you both. However, cnt's is the one I need. I will try it in a second... |
|
|
| Report Abuse |
|
|
|
| 18 Mar 2014 06:44 PM |
| don't use cnts, his will stop at 1, not 0, mine also is more efficient |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 18 Mar 2014 06:45 PM |
| No, mine will stop at zero, and yours won't reset when he changes the value and it's not more efficient. |
|
|
| Report Abuse |
|
|
|
| 18 Mar 2014 07:58 PM |
| @cnt, yours broke my whole game - @park, how do you make it go back to 60 when its done counting down? |
|
|
| Report Abuse |
|
|
|
| 18 Mar 2014 08:40 PM |
I'll be honest, scripting from a phone is hard, especial if you can't debug your own code.
Try removing the 1st while true loop in cnt's script. I think that might be the cause of the problem.
---------------- local timer = script.Parent.Parent.GameV
while timer.Value > 0 do timer.Value = timer.Value - 1 wait(1) end --anything under here will run when the timer is done timer.Value = 3 ----------------
|
|
|
| Report Abuse |
|
|