--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?
--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
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
--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
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.
--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.
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.