Ban GUI is banning the whitelisted player saying that they exploited when they were whitelisted?

Hello everyone. I made this script:

local DSS = game:GetService("DataStoreService")

local allowedToUse = {"MrOofBoyPlayz", "BigBanHam"}

local Bans = DSS:GetDataStore("Bans_[Code Censored]")

game.Players.PlayerAdded:Connect(function(player)
	for _, plr in pairs(allowedToUse) do
		if player.Name == plr then
			script.AdminTools:Clone().Parent = player.PlayerGui
		end
	end

	local data

	local s, e = pcall(function()
		data = Bans:GetAsync(player.UserId)
	end)

	if data ~= nil then
		player:Kick("Oof! Seems like you was banned by a moderator. Reason: '"..data.."'. Add 'Ban Appeal | Offical#0297' on discord and DM them with your roblox username + a good reason to get unbanned.")
	elseif data == "exploited" then
		player:Kick("Get outta here exploiter.")
	elseif data == "attemptbanowner" then
		player:Kick("Next time, don't try banning me!")
	end
end)

game.ReplicatedStorage.Ban.OnServerInvoke = function(player, playerToBan, reason)
	if playerToBan == "MrOofBoyPlayz" then
		Bans:SetAsync(player.UserId, "attemptbanowner")
		player:Kick("MrOofBoyPlayz: Uno Reverse Card! Your banned!")
	end

	for _, plr in pairs(allowedToUse) do
		if player.Name == plr then
			local realPlayer = game.Players:FindFirstChild(playerToBan)
			if realPlayer then
				Bans:SetAsync(realPlayer.UserId, reason)
				realPlayer:Kick("Oof! Seems like you was banned by a moderator. Reason: '"..reason.."'. Add 'Ban Appeal | Offical#0297' on discord and DM them with your roblox username + a good reason to get unbanned.")
			end
		else
			Bans:SetAsync(player.UserId, "exploited")
			player:Kick("I see you are exploiting, well good luck rejoining because you are banned!")
		end
	end
end

game.ReplicatedStorage.Unban.OnServerInvoke = function(player, playerToUnban)	
	for _, plr in pairs(allowedToUse) do
		if player.Name == plr then
			local reason = Bans:GetAsync(plr.UserId)
			local realPlayer = game.Players:GetUserIdFromNameAsync(playerToUnban)
			if realPlayer then
				Bans:RemoveAsync(realPlayer, reason)
			end
		else
			Bans:SetAsync(player.UserId, "exploited")
			player:Kick("I see you are exploiting, well good luck rejoining because you are banned!")
		end
	end
end

And when the whitelisted player (allowedToUse) bans someone, they get banned with the exploiting reason. Could somebody help me with this? I don’t want the whitelisted player to get banned.

2 Likes

You forgot to break out of the for loop.

1 Like

Ah ok, let me try this, thanks.

Well then, let’s see.

First of all, it would seems that the lines causing this issue would be your if player.Name == plr then check on the Ban.OnServerInvoke function. Now, according to this code, when a client fires the event, it goes through BOTH players on the allowedToUse list and checks if they are them.

Now, the first time, the check passes, because you are MrOofBoyPlayz, but the second time, it checks if you’re also BigBanHam, but you’re not, so it kicks you. As @SansariGames said, you have to add a return if it finds that you are allowed to ban.

Also, I kinda chuckled at the ban messages.

Hope i helped!

2 Likes

I think I fixed it thanks to @SansariGames, like I said, let me check

1 Like

I’m confused. This post isn’t about GUI?

1 Like