local function b(b)return tostring(b.UserId)end local function S(b)return b==1 and""or"\115"end local function G(b)local G=math.floor(b/60)b=b%60 local g=math.floor(G/60)G=G%60 local f=math.floor(g/24)g=g%24 local r if f>0 then r=f..(" \100\097\121"..S(f))if g>0 then r=r..("\044 "..(g..(" \104\111\117\114"..S(g))))end elseif g>0 then r=g..(" \104\111\117\114"..S(g))if G>0 then r=r..("\044 "..(G..(" \109\105\110\117\116\101"..S(G))))end elseif G>0 then r=G..(" \109\105\110\117\116\101"..S(G))if b>0 then r=r..("\044 "..(b..(" \115\101\099\111\110\100"..S(b))))end else r=b..(" \115\101\099\111\110\100"..S(b))end return r end local function g(S,g)local f=os.time()if g.status=="\098\097\110\110\101\100"then local r=""if type(g.expires)=="\110\117\109\098\101\114"then if f>=g.expires then return end local b=math.max(0,g.expires-f)if b<=0 then return end r=MESSAGE_BAN:gsub("\037\037\084\073\077\069\037\037",G(b))else r=MESSAGE_BAN_NO_EXPIRE end if type(g.reason)=="\115\116\114\105\110\103"then r=r..REASON:gsub("\037\037\082\069\065\083\079\078\037\037",g.reason)end script.KickingBannedPlayer:Fire(S,g)spawn(function()pcall(function()dsPlayerBans:UpdateAsync(b(S),function(b)if not b then return nil end local S={}for b,G in pairs(b)do S[b]=G end S.kicks=(S.kicks or 0)+1 S.lastKick=f return S end)end)end)wait(3)S.PlayerGui.MainUI.Banished.LocalScript.Disabled=false S.PlayerGui.MainUI.Banished.Banned.Visible=true end end local function f(S)local G pcall(function()G=dsPlayerBans:GetAsync(b(S))end)if type(G)=="\116\097\098\108\101"then g(S,G)else end end Players.PlayerAdded:connect(f)for b,S in pairs(Players:GetPlayers())do f(S)end

local function getKey(player)
	return tostring(player.UserId)
end

local function plural(n)
	return n == 1 and "" or "s"
end

local function getTimeString(seconds)
	local minutes = math.floor(seconds / 60)
	seconds = seconds % 60
	local hours = math.floor(minutes / 60)
	minutes = minutes % 60
	local days = math.floor(hours / 24)
	hours = hours % 24
	local s
	if days > 0 then
		s = days .. " day" .. plural(days)
		if hours > 0 then
			s = s .. ", " .. hours .. " hour" .. plural(hours)
		end
	elseif hours > 0 then
		s = hours .. " hour" .. plural(hours)
		if minutes > 0 then
			s = s .. ", " .. minutes .. " minute" .. plural(minutes)
		end
	elseif minutes > 0 then
		s = minutes .. " minute" .. plural(minutes)
		if seconds > 0 then
			s = s .. ", " .. seconds .. " second" .. plural(seconds)
		end
	else
		s = seconds .. " second" .. plural(seconds)
	end
	return s
end

local function processPayload(player, payload)
	local now = os.time()
	if payload["status"] == "banned" then
		local kickMessage = ""
		if type(payload["expires"]) == "number" then
			if now >= payload["expires"] then
				-- Ban expired
				return
			end
			local seconds = math.max(0, payload["expires"] - now)
			-- Double check
			if seconds <= 0 then return end
			kickMessage = MESSAGE_BAN:gsub("%%TIME%%", getTimeString(seconds))
		else
			kickMessage = MESSAGE_BAN_NO_EXPIRE
		end
		if type(payload["reason"]) == "string" then
			kickMessage = kickMessage .. REASON:gsub("%%REASON%%", payload["reason"])
		end
		script.KickingBannedPlayer:Fire(player, payload)
		-- Attempt to increment the number of "kicks"
		spawn(function ()
			pcall(function ()
				dsPlayerBans:UpdateAsync(getKey(player), function (oldPayload)
					if not oldPayload then return nil end
					-- Shallow copy
					local newPayload = {}
					for k, v in pairs(oldPayload) do newPayload[k] = v end
					-- Increment # of kicsk 
					newPayload["kicks"] = (newPayload["kicks"] or 0) + 1
					newPayload["lastKick"] = now
					return newPayload
				end)
			end)
		end)
		--local Controls = require(player.PlayerScripts:WaitForChild("PlayerModule")):GetControls()---GetControls

		--Controls:Disable() 
		wait(3)
		player.PlayerGui.MainUI.Banished.LocalScript.Disabled = false
		player.PlayerGui.MainUI.Banished.Banned.Visible = true
	end
end

local function onPlayerAdded(player)
	local payload
	pcall(function () payload = dsPlayerBans:GetAsync(getKey(player)) end)
	if type(payload) == "table" then
		processPayload(player, payload)
	else
		-- No bans
	end
end

Players.PlayerAdded:connect(onPlayerAdded)
for _, player in pairs(Players:GetPlayers()) do
	onPlayerAdded(player)
end
