Attempting to do time calculations with Unix returns nothing?

I have some code that I am writing, which connects with a Discord webhook. I am creating this for a help system in my game, so you can call and get help from moderators. The Discord part works great, however I want the player to only send a request once every hour. I decided to use Unix Time, or os.time() as I believe this to be the easiest way (and accurate) to figure out if it has been an hour or not.

local lastCalled --Defining the variable to assign the last time the player attempted to call
		
		local success, error = pcall(function()
			lastCalled = timeLimits:GetAsync(player.UserId) or 0 --Setting to an INT (Important)
		end)
		
		if success and math.abs(os.time() - lastCalled) > 3600 then --Checking if it's been an hour
			timeLimits:SetAsync(player.UserId, os.time()) --Setting the current time
			
			local data = {} --Discord Webhook stuff

			local encode = http:JSONEncode(data) --Discord Webhook stuff
			http:PostAsync(webhook, encode) --Discord Webhook stuff
			
			return true --Returning true, as the request was successfully sent
			
		else
			print(os.time() - tonumber(lastCalled)) --Printing the result (See below attachment)
			return (os.time() - tonumber(lastCalled)) --Returns if it hasn't been an hour, to tell the user how long they need to wait
			
		end

This code has a strange error,
attempt to perform arithmetic (div) on boolean and number

I do not understand the origion of this error. From the above code, all formats are saved in an INT format, and nothing is being changed to a boolean. This is a one time only thing, as after attempting to send another request, this error is gone and the code functions as normal, with all calculations to convert to minutes working in the next script. When printing the return from the return equation, it prints nothing.

what

If it helps, there is this other script that simply outputs the results to the player

script.Parent.Parent.title.Text = "Wait "..tostring(math.floor(60 - result/60)).. " more minutes"

Everything here is saved in the INT format too, so I am unaware of the issue.

I don’t see any issues… Maybe initialize lastCalled with nil and remove the “or 0” portion, and just return if nil?

This is probably the source of the error

Can you show the code from this script:

which checks, using result, if it failed or sent?

1 Like

I think you’re right. The return is just in the middle of an if statement… Not a function