so in my game i will have units that can be bought and they are bought through a timer sorta thing where it takes like 10 seconds to make a soldier. so i am going to use coroutines to make the que for them but coroutines are relatively new to me and i am confused on how to use them if i dont know how many that i will need at any given time. so could someone please clarify this for me. thank you.
✓ ANSWER ACCEPTED
help with coroutines?
1 answer
✓ Accepted answer
For this, you would not use coroutines. You would use a table.
local Queue = {"Soldier", "Soldier"}
spawn(function()
while wait(10) do
local I = table.remove(Queue, 1)
--Create your soldier. I is the name of the type or whatever you would do..
end
end)
Update:
The OP wanted to have different times for different units. Here's how:
local Queue = {"Soldier", "Tank"}
spawn(function()
while wait() do
local I = table.remove(Queue, 1)
if I == "Soldier" then
wait(10)
--Create soldier
elseif I == "Tank" then
wait(20)
--Create tank
end
end
end)
This discussion is preserved as it was. New answers, comments, and votes are closed.

4 comments
Please accept if this works.
just out of curiosity how would i handle different wait times with different units?
There, I updated my post.
thanks