I am working on a script that turns the tick() function into hours and minutes, but the for loop errors:
function isInt(number) return number == math.floor(number) end while true do wait() local times = math.floor(tick()) print(times) for i = 1,tick do if isInt(i/60) == true then script.Minute.Value = script.Minute.Value+ 1 end if isInt(script.Minute.Value/60) then script.Minute.Value = 0 script.Hour.Value = script.Hour.Value + 1 end if isInt(script.Hour.Value/24) then script.Hour.Value = 0 end end script.Parent.Text = script.Hour.Value.. " : ".. script.Minute.Value end
The output goes like this: 18:35:49.863 - Players.Player.PlayerGui.Phone.Main.Bar.Clock.TextLabel.LocalScript:8: 'for' limit must be a number 18:35:49.863 - Stack Begin 18:35:49.864 - Script 'Players.Player.PlayerGui.Phone.Main.Bar.Clock.TextLabel.LocalScript', Line 8 18:35:49.864 - Stack End
Please help me
tick
is not a number. It's a function that returns a number.
I think you meant to use times
.
Be warned that tick()
returns extremely large numbers, so I dont think this is a good way to go about doing this. Consider using the % operator and division instead.
EDIT: In particular, if you're only interested in the hour and minute, you can use
local times = tick() % (60 * 60 * 24)
which will make your code be much faster -- you shouldn't have to change anything else. This just "wraps around" the number of seconds at the end of a day.
You should also probably use local
variables instead of incrementing IntValues. It will be much faster, and cleaner code. If for some reason you need to save to the IntValues, just do it at the end.
In fact, you can avoid the iteration altogether if you do the same thing for the day as you do for each smaller subdivision:
local t = tick() local seconds = math.floor(t % 60) local minutes = math.floor(t / 60 % 60) local hours = math.floor(t / 60/ 60 % 24)
Here is a module I wrote that does this and more.