Why ban not counting!

hi
i made a temp ban system thingy and thing is it wont count all the way to zero if i ban someone

			local currenttime = os.time()
			local unbantime = currenttime + length
			local timeleft = unbantime - currenttime

if its not enough then plz tell me my brain gave up and ive been staring at these lines of code for 30 mins

1 Like

What is length?
os.time() returns the current unix timestamp in seconds. Make sure that your length variable is in seconds.

store the time the ban started

ok so length is the time in seconds the player has been banned for

i use datastore2 to store the ban data.

players.PlayerAdded:Connect(function(plr)
	local bandata = datastore2module("Banned", plr)
	local admindata = datastore2module("Admin", plr)
	local lengthdata = datastore2module("Time", plr)
	local reasondata = datastore2module("Reason", plr)
	local banned, admin, length, reason

	local success, err = pcall(function()
		banned = bandata
		admin = admindata
		length = lengthdata
		reason = reasondata
	end)

	local function updatebandata(updtval)
		banned = bandata:Get(updtval)
	end
	local function updateadmindata(updtval)
		admin = admindata:Get(updtval)
	end
	local function updatelengthdata(updtval)
		length = lengthdata:Get(updtval)
	end
	local function updatereasondata(updtval)
		reason = reasondata:Get(updtval)
	end

	updatebandata(defaultbanval)
	updateadmindata(defaultmodval)
	updatelengthdata(defaultbantime)
	updatereasondata(defaultbanreason)

	print(banned)
	print(length)

	if banned == true then
		if tonumber(length) then
			local currenttime = os.time()
			local unbantime = currenttime + length
			local timeleft = unbantime - currenttime
			print(currenttime, unbantime, timeleft, length)
			if timeleft <= 0 then
				bandata:Set(false)
			else
				local banmsg = generatebanmsg(admin, reason, false)..formattime(timeleft)

				lengthdata:Set(timeleft)
				plr:Kick(banmsg)
			end
		elseif length == "perm" then
			local banmsg = generatebanmsg(admin, reason, true)

			plr:Kick(banmsg)
		end
	end
end)

heres the whole script (not really)
image
currenttime, unbantime, timeleft, length.

1 Like

you arent storing the time the ban started just the length try storing the time it ends instead

1 Like

image
how.
im storing the time and then changing it to timeleft if player joins while banned

why are you adding current time to length then removing currenttime its just going to be if length <= 0 which it never will be

1 Like

my god you took me out of brain rot thingy i actually know what to do now!!! i will try making the length (in secs) os.time() + length!

lemme just unban myself lol

it work thank you!!!

aaaa character limit mean :frowning:

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