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

How do I do a wait(1) in a while true do loop without delaying the loop by 1 second?

I'm trying to wait 1 second then destroy an object, but it delays the loop by one second. I've tried to use the variable outside of the loop, but that doesn't work either.

note: i'm cloning a bullet shell locally

1 answer

✓ Accepted answer

You can do this multiple ways, here is a couple...

while true do
	local part = Instance.new("Part)
	part.Parent = workspace

	game.Debris:AddItem(part, 1) -- Gets destroyed after 1 second
end

or

while true do
	local part = Instance.new("Part)
	part.Parent = workspace

	coroutine.wrap(function()
		wait(1)
		part:Destroy()
	end)()
end

I prefer the first example, but sometimes the second one is necessary for specific reasons.

1 comment

0

you god

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