Why does this still kick me

Recently i’ve made a ban script, which obviously checks if you’re banned and then kicks the player, the problem is that i am trying to check if the players UserId is not equal to the CreatorsId or if the player has not the rank Admin, if so the server will kick the player, if they do have the Admin rank or if the player is the creator it won’t kick them, the problem is that even with the Admin rank and being the creator it still kicks me out of the game, i honestly do not know how i would it stop it from kicking the creator or an administrator out of the game.

Players.PlayerAdded:Connect(function(Player)
	local BanData
	local Success,ErrorMessage = pcall(function()
		BanData = BanDatastore:GetAsync(BanKey..Player.UserId)
	end)
	local RankData = RankDatastore:GetAsync(RankKey..Player.UserId)
	if Success then
		if not BanData then
			local Success,ErrorMessage = pcall(function()
				BanDatastore:SetAsync(BanKey..Player.UserId,{IsBanned = false,Moderator = "",Reason = "",BannedAt = 0})
			end)
			if not Success then
				warn("Error: "..ErrorMessage)
			end
		elseif BanData then
			if BanData.IsBanned then
				if Player.UserId ~= game.CreatorId or RankData ~= "Admin" then
					Player:Kick("\nYou've been banned out of ".. game.Name.."\nModerator: ".. BanData.Moderator.."\nReason: ".. BanData.Reason.."\n\n[ Banned at: ".. os.date('%c',BanData.BannedAt).." ]")
				end	
			end
		end
	elseif not Success then
		warn("Error: "..ErrorMessage)
	end
end)

Try to change the or statement to an And

1 Like

Add code that doesn’t ban you if you’re on a table of admins. It shouldn’t be hard to update a table for a handpicked role.

I don’t want the creator to also add them as an administrator.

I’m storing the Admin rank on a datastore, with each rank has it’s own key e.g: ~Rank:Data~Players UserId

Found a solution for it:

Players.PlayerAdded:Connect(function(Player)
	local BanData
	local Success,ErrorMessage = pcall(function()
		BanData = BanDatastore:GetAsync(BanKey..Player.UserId)
	end)
	local RankData = RankDatastore:GetAsync(RankKey..Player.UserId)
	if Success then
		if not BanData then
			local Success,ErrorMessage = pcall(function()
				BanDatastore:SetAsync(BanKey..Player.UserId,{IsBanned = false,Moderator = "",Reason = "",BannedAt = 0})
			end)
			if not Success then
				warn("Error: "..ErrorMessage)
			end
		elseif BanData then
			if BanData.IsBanned then
				if Player.UserId == game.CreatorId then
					warn("This wasn't supposed to happen.")
				elseif RankData == "Admin" then
					warn("This wasn't supposed to happen.")
				else
					Player:Kick("\nYou've been banned out of ".. game.Name.."\nModerator: ".. BanData.Moderator.."\nReason: ".. BanData.Reason.."\n\n[ Banned at: ".. os.date('%c',BanData.BannedAt).." ]")
				end
			end
		end
	elseif not Success then
		warn("Error: "..ErrorMessage)
	end
end)