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)