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..

local cashh = Instance.new("IntValue")
cashh.Parent = ack
cashh.Name = "Wheels"
cashh.Value = 0
local cash = Instance.new("IntValue")
cash.Parent = ack
cash.Name = "Tires"
cash.Value = 0
while true do
    wait(120)
    cash.Value = cash.Value + 1
end 
while true do
    wait(2)
    cashh.Value = cashh.Value + 1
end 

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.

local cashh = Instance.new("IntValue")
cashh.Parent = ack
cashh.Name = "Wheels"
cashh.Value = 0
local cash = Instance.new("IntValue")
cash.Parent = ack
cash.Name = "Tires"
cash.Value = 0
coroutine.wrap(function()
    while true do
        wait(120)
        cash.Value = cash.Value + 1
    end 
end)()
while true do
    wait(2)
    cashh.Value = cashh.Value + 1
end 
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