How to avoid stack overflow error and also make wait function more accurate[Solved]?

The problem is that wait function is sometimes very slow, i mean that 1/60 of second is not enough, so i decided make my own wait function, but i stomped on this error.
Any suggestions how can i make a wait function other the way?

image

coroutine.resume(coroutine.create(function()
				local StartTime = tick()
				
				
				local N = 0
				local IterationsPerWait = 100
				local function WaitTill(Time)
					N += 1
					if IterationsPerWait <= N then
						N = 0
						wait()
					end
					
					if tick() - StartTime >= Time then
						return true
					end
					
					return WaitTill(Time)
				end
				
				WaitTill(CooldownsData[Type])
				
				self.CurrentCooldowns[Type] = nil
				
			end))

image

1 frame window of time is too slow for you?

Yes, exactly. It’s way too slow.
What if i would like to create a gun which fires 120 rounds per second?
I wont fire 2 bullets at the same time, as it’s a bit unrealistic.

I would just make the gun do twice the damage, I don’t really recommend needing something faster then 60th of a second, that going take up a lot more resources, players won’t be able to notice that difference, there also visual tricks you can play to make guns appear there shooting more then they actually are

3 Likes

The above solution or have the gun fire 2 bullets per frame.