I tried making it so for ex, when 5 seconds have passed without a function being run it prints something , what would I use for that?
to tell the elapsed time since an action, just set a variable to the current time whenever the action happens. To check the time just subtract the variable from the current time.
Example:
local lastUse = tick()
function whatever()
lastUse = tick() -- assign lastUse to the current time
task.delay(5,function() -- wait five seconds and then check if its been five seconds since the last time the action was used
if tick() - lastUse >= 5 then
print("5 seconds have passed since this action")
end
end)
-- do whatever the function needs to do
end
-- alternate way of checking (not reccomended)
while wait(0.5) do
if tick() - lastUse >= 5 then
print("5 seconds have passed since this action")
end
end
1 Like
I have heard that tick() should not be used anymore
@grandisy
i found a related post Does tick() function still work? - Help and Feedback / Scripting Support - DevForum | Roblox
I see very mixed opinions when I search about the topic
maybe this post could be of some use to solve your confusion:
The Ultimate os, time, and tick Tutorial! - Resources / Community Tutorials - DevForum | Roblox
Use DateTime class,
DateTime.now().UnixTimestamp
returns the same thing as tick()
and the other ones
1 Like