Attempt to perform arthimetic (sub) on number and table

Hello, recently I’m making a Ban admin panel with custom time bans, but I cannot figure this error out.image it didn’t occur until recently so I’m not too sure. Here is a little snippet on the code:

local BanStore = DDS:GetDataStore("BanStore") 
local banWait = 24

Players.PlayerAdded:Connect(function(plr)
	local banData
	
	pcall(function()
		banData = BanStore:GetAsync(plr.UserId)
	end)
	if banData then
		local Seconds = os.time() - banData
		local mins = Seconds/60
		local hrs = mins/60
		
		if hrs >= 24 then
			BanStore:RemoveAsync(plr.UserId)
			BanStore:SetAsync(plr.UserId, os.time())

		end
	else
		plr:Kick("You have been banned by an Administrator! (1 Day Ban)")
		BanStore:SetAsync(plr.UserId, os.time())
	end
end)

What’s… the uhh… error…? Can you just post it? I can’t help that much as i’m not bothered to set it up.

image

Hm, seems to be a problem with a table and number (well duh)

Does that number “64” correlate to the line? Or the value?

It correlates to this line: image

I think I know what. It must be that it makes a negative value. Not sure, make sure all values are valid, and hover over it if it shows any errors.

You should have a look at this, the value of the OS time doesn’t seem like seconds on here os | Documentation - Roblox Creator Hub

i think the error means you are trying to subtract a number by a table, please put

print(type(os.time()), type(banData))

before line 64 to make sure you are subtracting 2 numbers

2 Likes

You are trying to subtract an number with an table make sure you add typeof(banData) To see what type of variable the banData is

1 Like

It didn’t work, I am subtracting a number table but I used :SetAsync() with os.time() as the second parameter.

BanStore:SetAsync(plr.UserId, os.time())

what do you mean It didn’t work, does it error? if so, what is the error?

And also it’s best to assign a variable in a pcall function and replace the if banData statement to if success if you assigned it this way

local success,errormessage = pcall(function()
		banData = BanStore:GetAsync(plr.UserId)
	end)

Attempt to perform arthimetic (sub) on string

Then this might be because the banData variable turned into a string value. Luckily you can convert it into an int value (a.k.a number value) by simply typing this inside of a banData if statement just to be clear im not sure if this will function properly

if banData then
        tonumber(banData)
        local Seconds = os.time() - banData
        --Rest of the script here
end

Can I ask what DDS is? Is it DataStore Service? A custom datastore module?

DDS is holding the Datastoreservice