Hello! I need a simple amount of time for a time played function for my new Café. I want to give my workers 1 time played every minute.
My issue is that I do not know the time converter from Roblox wait() to seconds.
I have looked for solutions on YT and could not find anything related to the topic
I need to know what time to put in the command wait() to wait 1 full minute
-- other stuff above
wait(60)
-- adds a point, but i do not know if this is an exact minute
Wait takes times as seconds so wait(60)
should yield code for a minute or something close to that but it’s not 100% accurate so it might yield for maximum 1 or 2 seconds more that it should be.
Thanks for the help! I will be using wait(60)!
wait(1) -- 1 seconds
wait(2) -- 2 seconds
wait(0.1) -- waits 100 ms / 0.1 seconds
However, there’s an issue here of a scenario where the player leaves mid-game and the wait ends and it just errors. Attempting to band-aid solution this with the if
statement to check for the player doesn’t really work when the player returns after disconnecting quickly.
For a better solution, consider this:
local start = os.clock() -- starting time which is in seconds, read more on Developer Hub
while player.Parent do -- do not use while wait() do
wait() -- can be alternated to RunService.Heartbeat:Wait()
if os.clock() - start >= 60 then
-- code for award
end
end
Using this code pattern above in combination with PlayerAdded
event, which is proven efficient.