How to use wait in RunService

Please read the title before answering this question.
I do not want to be told to use the while wait option
I just want to know how i can use wait in runservice just like how you can use wait in a While True function. If there is no possible way just inform me about it. Any Help is appreciated!

Are you thinking about this??

game:GetService("RunService").Stepped:wait()

or…

game:GetService("RunService").RenderStepped:Connect(function()
        print("lol rip dev console")
end)
1 Like

Nope, as in a code similar to this

RunService.Heartbeat:Connect(function()
wait(1)
end)

and it would actually wait one second, this is just an example its just possible like that

The second option is more of it but i want to see if its possible to use wait in it

Something like this I believe

local debounce = false

RunService.Heartbeat:Connect(function()
	if debounce then
		return
	end
	debounce = true
	wait(1)
	print("This prints every second")
	deboune = false
end)

Basically, debounce, not sure why this is necessary when a while loop suffices, unless it is required to wait at some point

1 Like

It’s possible for sure, I just wouldnt see why you would do that.

After all, it would just be easier to use while wait(1) do

1 Like

Remember doing the white wait would cut off the rest of the script since it would not execute anything under it.

oh! thats your issue?

easy fix

spawn(function()
while true do
wait(1)
print("THIS SCRIPT IS NOT YIELDING :D")
end
end)
1 Like

Can’t you coroutine the while loop?

coroutine.wrap(function()
	while true do
		wait(1)
		print("One second")
	end
end)()
1 Like

This works so thanks and i believe the 4th 5th and 6th line can be merged into 1

I’ll test it out and see if its more efficient

Don’t use spawn or coroutine.wrap too frequently

but yes spawn and coroutine.wrap are kinda the same thing

1 Like

Yes it can but I generally space them out since I prefer the readability

Also spawn can be considered the same as coroutine.wrap but spawn waits until the next cycle, which basically means a wait() and then it executes what you want, which can be a problem as a wait() can be longer than expected, whereas a coroutine doesn’t have this issue I believe

2 Likes

most of my scripts use spawn because i use it for recoil in a fps game I’m making so thats an exception

Thanks for both of you guys help this will be useful to me in the long run!

1 Like

Glad to be of help! iIf you have anymore issues don’t be afraid to make another post!