You can use tick()
Yes, I know people say it’s deprecated.
So, tick() gets the amount of seconds passed since January 1st 1970. Lol I know right! Why did Roblox even make this you may ask? Tick can be helpful if you’re creating some kind of a system that requires a timestamp of some sort, such as debouncing or cooldowns or whatever. So let me show you what we can do with tick().
local start = tick() --UNIX Epoch time in seconds
print("Hi")
while true do
wait()
if tick() - start >= 5 then
print("Bye")
break
end
end
Of course it would look better as a debounce and not usage for a while loop if you get what I mean?
Let me demonstate an example
local start = tick()
--Let's say tick() is equal to 20 in this case
--Every second it incements by 1 (if you think in seconds)
part.Touched:Connect(function()
if tick() - start >= 3 then
start = tick()
print("Part Touched and successfully ran debounce")
end
end)