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.
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.