Custom Ban Panel Banning myself Incidentally

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

A functioning ban panel that will effectively ban said user for said amount of time.

  1. What is the issue? Include screenshots / videos if possible!

When I try to ban another account, it doesn’t ban the other user and instead bans me.

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I have used the developer hub to help with DSes as well as RemoteEvents. I haven’t tried much, I don’t have a great idea of why my Script won’t work.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

LocalScript code, inside of a TextButton

script.Parent.MouseButton1Click:Connect(function()
	local usr = tostring(script.Parent.Parent.Username.Text)
	local rsn = tostring(script.Parent.Parent.Time.Text)
	local banTime = tostring(script.Parent.Parent.Reason.Text)
	game.ReplicatedStorage.BanUser:FireServer(usr, rsn, banTime)
end)

ServerScript code, inside of ServerScriptService

local function banUser(user, usr, rsn, banTime)
	local dataStore = game:GetService("DataStoreService")
	local bansStore = dataStore:GetDataStore("BansStore")
	bansStore:SetAsync(usr.."user", usr)
	bansStore:SetAsync(usr.."reason", rsn)
	bansStore:SetAsync(usr.."status", true)
	user:Kick("You are banned from Fenix Hotels.\nReason: "..rsn.."\n You will be unbanned in "..banTime.." day(s)")
	local currentBanTime = os.time()
	local daysToSecs = banTime * 86400
	local timeAtUnban = tonumber(currentBanTime) + tonumber(daysToSecs)
	bansStore:SetAsync(usr.."time", banTime)
	bansStore:SetAsync(usr.."timeAtUnban", timeAtUnban)
	print("!!BAN LOG!!", usr, "was banned for", rsn, "and will be unbanned in", banTime, "day(s)")
end

game.Players.PlayerAdded:Connect(function(plr)
	local usr = plr.Name
	local dataStore = game:GetService("DataStoreService")
	local bansStore = dataStore:GetDataStore("BansStore")
	local usr = bansStore:GetAsync(usr.."user")
	local banStatus = bansStore:GetAsync(usr.."status")
	local banReason = bansStore:GetAsync(usr.."reason")
	local timeAtUnban = bansStore:GetAsync(usr.."timeAtUnban")
	local banTimeRemaining = bansStore:GetAsync(usr.."time")
	local currentTime = os.time()
	if banStatus == true and usr == plr.Name and timeAtUnban > currentTime then
		plr:Kick("You are banned from Fenix Hotels.\nReason: "..banReason.."\n You will be unbanned in "..banTimeRemaining.." day(s)")
	else
		return false
	end
end)

game.ReplicatedStorage.BanUser.OnServerEvent:Connect(banUser)

Any Ideas?

(My bad if any parts are inefficient, I wrote the majority late at night.)

I think I can have the problem but I need test.

I’m guessing that because when you fire an event, the first argument is the player that fired it to the server. Here your kicking yourself because your the player who sent the remote.

user:Kick("You are banned from Fenix Hotels.\nReason: "..rsn.."\n You will be unbanned in "..banTime.." day(s)")

user = the player that sent the remote(you)
usr = the player your wanting to ban

You should use different variable names so you dont get confused

local function banUser(localPlayer, kickPlayer, rsn, banTime)
	local dataStore = game:GetService("DataStoreService")
	local bansStore = dataStore:GetDataStore("BansStore")
	bansStore:SetAsync(kickPlayer.."user", kickPlayer)
	bansStore:SetAsync(kickPlayer.."reason", rsn)
	bansStore:SetAsync(kickPlayer.."status", true)
	kickPlayer:Kick("You are banned from Fenix Hotels.\nReason: "..rsn.."\n You will be unbanned in "..banTime.." day(s)")
	local currentBanTime = os.time()
	local daysToSecs = banTime * 86400
	local timeAtUnban = tonumber(currentBanTime) + tonumber(daysToSecs)
	bansStore:SetAsync(kickPlayer.."time", banTime)
	bansStore:SetAsync(kickPlayer.."timeAtUnban", timeAtUnban)
	print("!!BAN LOG!!", kickPlayer, "was banned for", rsn, "and will be unbanned in", banTime, "day(s)")
end

That helps me a lot! I’ll give it a try.

2 Likes

Also you dont need tostring here, because the Text property is always a string, even if the text is 12345. But I sometimes do this to, just incase you know

2 Likes