Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can i make twice "while true do" in one script?

Asked by 9 years ago

How can i make twice "while true do" in one script? bc this is not working..

01local cashh = Instance.new("IntValue")
02cashh.Parent = ack
03cashh.Name = "Wheels"
04cashh.Value = 0
05local cash = Instance.new("IntValue")
06cash.Parent = ack
07cash.Name = "Tires"
08cash.Value = 0
09while true do
10    wait(120)
11    cash.Value = cash.Value + 1
12end
13while true do
14    wait(2)
15    cashh.Value = cashh.Value + 1
16end

1 answer

Log in to vote
4
Answered by
NotSoNorm 777 Moderation Voter
9 years ago

What you're look for is coroutine, It creates a new thread that doesn't interrupt the script. It can also use variables that the script has also, There are some others related to coroutine, like for example spawn, But I don't really know how to use. This works just fine.

01local cashh = Instance.new("IntValue")
02cashh.Parent = ack
03cashh.Name = "Wheels"
04cashh.Value = 0
05local cash = Instance.new("IntValue")
06cash.Parent = ack
07cash.Name = "Tires"
08cash.Value = 0
09coroutine.wrap(function()
10    while true do
11        wait(120)
12        cash.Value = cash.Value + 1
13    end
14end)()
15while true do
16    wait(2)
17    cashh.Value = cashh.Value + 1
18end
0
Do not forget the extra () after the coroutine.wrap Either that or you can use the spawn method which works the same way. M39a9am3R 3210 — 9y
0
Use `spawn` instead, it's cleaner, shorter, and shows intent better! BlueTaslem 18071 — 9y
Ad

Answer this question