Ban System Script Isnt Working

I’m developing a GUI for game admins to ban users, but I’m facing code errors. Buttons set ban days, turning red when clicked, and back to white when another day button is clicked. The clicked button determines the ban duration. A data store saves bans during shutdown or rejoin, and the game automatically unbans users after their time is up. I’ve run into issues with my code, and I’d love it if someone could help resolve them. Thanks!

BUTTON_COLORS_CODE

for i,v in pairs(days) do
		v.MouseButton1Click:Connect(function()
			for a,b in pairs(days) do
				if b.BackgroundColor3 == Color3.fromRGB(255, 0, 0) then
					b.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
				end
			end
			v.BackgroundColor3 = Color3.fromRGB(255, 0, 0)
		end)
	end

BAN_LENGTH

local banlength = 1
	if days.ONE.BackgroundColor3 == Color3.fromRGB(255, 0, 0) then
		banlength = 1
	elseif days.THREE.BackgroundColor3 == Color3.fromRGB(255, 0, 0) then
		banlength = 3
	elseif days.FIVE.BackgroundColor3 == Color3.fromRGB(255, 0, 0) then
		banlength = 5
	end

BAN_PART

banDataStore:SetAsync(playerid, true)
	game.Players:GetPlayerByUserId(playerid):Kick("You have been banned for " .. banlength .. " days.")
	wait(banlength * 86400)
	banDataStore:RemoveAsync(playerid)

	local success, errormessage = pcall(function()
		banDataStore:SetAsync(playerid, "Banned")
	end)
	
	if success then
		print("Player has been banned for "..banlength.."day(s)")
	else
		warn(errormessage)
	end

FULL_CODE_ALL_TOGETHER

local days = {
	ONE = script.Parent.ONE,
	THREE = script.Parent.THREE,
	FIVE = script.Parent.FIVE
}

local DSS = game:GetService("DataStoreService")
local banDataStore = DSS:GetDataStore("banDataStore")

script.Parent.BAN.MouseButton1Click:Connect(function()
	
	local playerid = game.Players:GetUserIdFromNameAsync(script.Parent.PLAYERNAME.Text)
	
	for i,v in pairs(days) do
		v.MouseButton1Click:Connect(function()
			for a,b in pairs(days) do
				if b.BackgroundColor3 == Color3.fromRGB(255, 0, 0) then
					b.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
				end
			end

			v.BackgroundColor3 = Color3.fromRGB(255, 0, 0)
		end)
	end
	
	local banlength = 1
	if days.ONE.BackgroundColor3 == Color3.fromRGB(255, 0, 0) then
		banlength = 1
	elseif days.THREE.BackgroundColor3 == Color3.fromRGB(255, 0, 0) then
		banlength = 3
	elseif days.FIVE.BackgroundColor3 == Color3.fromRGB(255, 0, 0) then
		banlength = 5
	end

	banDataStore:SetAsync(playerid, true)
	game.Players:GetPlayerByUserId(playerid):Kick("You have been banned for " .. banlength .. " days.")
	wait(banlength * 86400)
	banDataStore:RemoveAsync(playerid)

	local success, errormessage = pcall(function()
		banDataStore:SetAsync(playerid, "Banned")
	end)
	
	if success then
		print("Player has been banned for "..banlength.."day(s)")
	else
		warn(errormessage)
	end
		
end)

Surely the wait time would not work would it not? As the server should shut down after x amount of time discontinuing the code. Would it not be better to log the day of which the user last joined, then the day of which they can rejoin (and onward)?

Probably would; could you explain on how I could do that?

I haven’t completely looked into getting a players date. However, I looked through this and it’s a very simple explanation on how os.time works : D!

Do you know around like where I’d put os.time

Sadly no, I’m not completely sure on the subject all I can assume is that you may need to make a function for retrieving a players time and outputting an unban date alongside having a script check for whether or not the day is met or passed.

I believe I have added the OS time; however, I’m also concerned about the button changing colors thing. Could you potentially help me out with that? Thanks.

Sure! Could you explain exactly the issue you’re having and what you would like to happen instead? (If possible could you provide me with some visuals to get an idea)

I’m unsure how I could get a visual; however, I am able to explain what I’d like.

So essentially, with the buttons, they’re currently white. What I want to happen is that when I click on it, the button’s background color turns to red, and if they click on it again, it turns back to white. If it’s red, that’s how many days they’re banned.

for i,v in pairs(days) do
	v.MouseButton1Click:Connect(function()
		for _, Button in pairs(days) do
			if Button == v and v.BackgroundColor3 == Color3.fromRGB(255, 255, 255) then
				v.BackgroundColor3 = Color3.fromRGB(255, 0, 0)
			else
				v.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
			end
		end
	end)
end

Would this be what you’re looking for?

The code you put above isn’t working unfortunately.

Any errors? Also, have you made sure that the references are correctly set, as well as have you tested if the background colour does actually change outside of the game?