Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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 

2 comments

0

Do not forget the extra () after the coroutine.wrap Either that or you can use the spawn method which works the same way.

0

Use spawn instead, it's cleaner, shorter, and shows intent better!

This discussion is preserved as it was. New answers, comments, and votes are closed.