Ban Command Banned Everyone

		--Ban Player
			elseif SplitCommand[1] == ":ban" or SplitCommand[1] == ":Ban" then
				local TargetedPlayer = SplitCommand[2]
				local Name = game.Players:FindFirstChild(TargetedPlayer)
				Name:Kick("You have been banned by a Blossom County Moderator. To appeal, join our Discord server linked below our game.")
				
				local Success, ErrorMessage  = pcall(function()
					BanDataStore:SetAsync(Player.UserId, true)
				end)
				if Success then
					Player:Kick("You have been banned by a Blossom County Moderator. To appeal, join our Discord server linked below our game.")
				else
					warn(ErrorMessage)
				end
				--Ban Player

Here’s my ban command code. When I tried it on an actual player in game it banned EVERYONE in the server. What’s the issue?

Oops I fixed my code my self. I realized the setasync thingy since it was a ban command I had to do name:Kick

Now it won’t even save the ban. Bruhhh

Are you checking that they exist in the ban data store when they try to join?

--Ban Player
			elseif SplitCommand[1] == ":ban" or SplitCommand[1] == ":Ban" then
				local TargetedPlayer = SplitCommand[2]
				local Name = game.Players:FindFirstChild(TargetedPlayer)
				Name:Kick("You have been banned by a Blossom County Moderator. To appeal, join our Discord server linked below our game.")
				
				local Success, ErrorMessage  = pcall(function()
					BanDataStore:SetAsync(Player.UserId, true)
				end)
				if Success then
					Name:Kick("You have been banned by a Blossom County Moderator. To appeal, join our Discord server linked below our game.")
				else
					warn(ErrorMessage)
				end
				
				--Ban Player
--Check if player is banned
game.Players.PlayerAdded:Connect(function(Player)
	local Banned
	local Success, ErrorMessage  = pcall(function()
		Banned = BanDataStore:GetAsync(Player.UserId)
	end)
	if Banned == true then
		Player:Kick("You have been banned by a Blossom County Moderator. To appeal, join our Discord server linked below our game.")
	end
	if Success then

	else
		warn(ErrorMessage)
	end
end)
--Check if player is banned

Check my code down below. I’m not sure what’s the issue. So basically when I ban the person it kicks them and when they join back they legit aren’t abnned. AND WHEN I JOIN THE BACK AKA THE MODERATOR I GET BANNED

Ima try editing my own code. Let me see what I can do

I’m not certain about how pcall and async works, but it’s possible you’re testing Banned before the data is fully loaded. Try putting the player kick in the pcall. That, or it’s erroring, Does ErrorMessage provide any output?

				--Ban Player
			elseif SplitCommand[1] == ":ban" or SplitCommand[1] == ":Ban" then
				local TargetedPlayer = SplitCommand[2]
				local Name = game.Players:FindFirstChild(TargetedPlayer)
				Name:Kick("You have been banned by a Blossom County Moderator. To appeal, join our Discord server linked below our game.")
				
				local Success, ErrorMessage  = pcall(function()
					BanDataStore:SetAsync(Player.UserId, true)
				end)
				if Success then
					Player:Kick("You have been banned by a Blossom County Moderator. To appeal, join our Discord server linked below our game.")
				else
					warn(ErrorMessage)
				end
				
				--Ban Player
--Check if player is banned
game.Players.PlayerAdded:Connect(function(Player)
	local Banned
	local Success, ErrorMessage  = pcall(function()
		Banned = BanDataStore:GetAsync(Player.UserId)
	end)
	if Banned == true then
		Player:Kick("You have been banned by a Blossom County Moderator. To appeal, join our Discord server linked below our game.")
	end
	if Success then

	else
		warn(ErrorMessage)
	end
end)
--Check if player is banned

This is way too little code to understand what’s happening. I see no reason it should kick everyone. If SplitCommand[2] is invalid, :Kick should fail.


				--Ban Player
			elseif SplitCommand[1] == ":ban" or SplitCommand[1] == ":Ban" then
				local TargetedPlayer = SplitCommand[2]
				local Name = game.Players:FindFirstChild(TargetedPlayer)
				Name:Kick("You have been banned by a Blossom County Moderator. To appeal, join our Discord server linked below our game.")
				
				local Success, ErrorMessage  = pcall(function()
					BanDataStore:SetAsync(Player.UserId, true)
				end)
				if Success then
					Player:Kick("You have been banned by a Blossom County Moderator. To appeal, join our Discord server linked below our game.")
				else
					warn(ErrorMessage)
				end
				
				--Ban Player

--Check if player is banned
game.Players.PlayerAdded:Connect(function(Player)
	local Banned
	local Success, ErrorMessage  = pcall(function()
		Banned = BanDataStore:GetAsync(Player.UserId)
	end)
	if Banned == true then
		Player:Kick("You have been banned by a Blossom County Moderator. To appeal, join our Discord server linked below our game.")
	end
	if Success then

	else
		warn(ErrorMessage)
	end
end)
--Check if player is banned

Where’s the rest of the code? Specifically the code that deals with command processing

Uhh the rest of the code is all of my admin commands

Then you clearly have an issue with your command processing. It isn’t possible for this code to kick more than one player at once, let alone the entire server.

IDEA! Let me try somethign rq I might have idea how to fix this

	--Ban Player
			elseif SplitCommand[1] == ":ban" or SplitCommand[1] == ":Ban" then
				local TargetedPlayer = SplitCommand[2]
				local Name = game.Players:FindFirstChild(TargetedPlayer)
				Name:Kick("You have been banned by a Blossom County Moderator. To appeal, join our Discord server linked below our game.")
				
				local Success, ErrorMessage  = pcall(function()
					BanDataStore:SetAsync(Player.UserId, true)
				end)
				if Success then
					
				else
					warn(ErrorMessage)
				end
				
				--Ban Player

--Check if player is banned
game.Players.PlayerAdded:Connect(function(Player)
	local Banned
	local Success, ErrorMessage  = pcall(function()
		Banned = BanDataStore:GetAsync(Player.UserId)
	end)
	if Banned == true then
		Player:Kick("You have been banned by a Blossom County Moderator. To appeal, join our Discord server linked below our game.")
	end
	if Success then

	else
		warn(ErrorMessage)
	end
end)
--Check if player is banned

Ok so where I did :setasync I took out the Player:Kick in the if Sucess statement. It now kicked that player and not me. BUT when I make that player rejoin she ain’t banned and when I rejoin aka the moderator it kicked me out.

So I’m thinking there’s an issue in the :GetASync statement.

Ok, I did some digging and found your issue is scope. pcall has its own scope, so you can’t just mess around with variables in and out like that. You must pass the UserId as an argument to your pcall function.
Go look up how it works.

Where would I pass the UserID argument?

Since I already passed it in the GetAsync and SetAsync You can see it in my code above