DateTime.now() isnt giving a number

The issue with the code is that it says
**ServerScriptService.Ban:36: attempt to perform arithmetic (mul) on nil and number **

Here is the line of code that is 36:

banService:SetAsync(plr.UserId, math.floor(tonumber(DateTime.now()) * 0.001))

For some reason, DateTime.now() isnt counted as a number. I want to use it in my ban system but its not working.

Here is my code:


game.Players.PlayerAdded:Connect(function(plr)

	for i,v in pairs(bannedPeople) do
		if v.UserId == plr.UserId then
			
			local check = banService:GetAsync(plr.UserId)
			
			if check == nil then
				banService:SetAsync(plr.UserId, math.floor(tonumber(DateTime.now()) * 0.001))
				plr:Kick("You have been banned for " .. v.Reason .. "! You will be unbanned in " .. v.Days .. " day(s)")
			else
				local tim = tonumber(DateTime.now()) * 0.001
				if tim > v.Days * 86400 + check then
					banService:SetAsync(plr.UserId, nil)
				else
					plr:Kick("You have been banned for " .. v.Reason .. "! You will be unbanned in " .. v.Days * 86400 + check - tim)
				end
			end
		
		end
	end
end)

DateTime.now doesn’t return a number, it returns a DateTime object. You may be confusing it with os.time, which returns the current unix time.

okay it worked. Its also nice to see that once I got that fixed my entire script started working. I guess the more you code the more you get the satisfaction of not messing your logic up. This is especially true for something complex like what I am making, where logic being messed up is easy to appear.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.