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
IDEA look at this image. Could the player be making it where the moderator gets banned??
Here is a handy guide. They work like anonymous functions.
local success, value = pcall(function(number)
return number + 5
end, 20)
print("pcall returns", success, value)
In this example, value is 25.
So practically we may do something like this:
local Success, ErrorMessage = pcall(function(banUserId)
BanDataStore:SetAsync(banUserId, true)
end, Name.UserId)
I also noticed that for some reason you are trying to add “Player” to the ban datastore? I figured that was a bug?
Nope, I fixed it. I just had to make the Player into Name.UserID in the :setasync
I guess that was the real bug. At any rate, be careful of scope leaking. I have no idea why it was possibly also banning every player, which sounds like a major issue.
What’s scope leaking? Adding characters
all i can really suggest is to use hdadmin. it is a bit buggy when it comes to bans (you cant re-ban someone after unbanning them unless you update the game and restart the servers), but itd certainly solve your problem.
Hmmm, I’m not fully sure if that’s true. I’ll test it out I’ll make a unban command. Then I’ll ban him then unban him and then ban him again. Let me see if it would work.
Time to use my brain to see how to make a unban commnad.
I think you mean when I do the unban command I’m going to set it to RemoveAsync where I’m actually going to set the value to false.
This topic is about a ban command, not a unban command. If you need help with your unban command, open a different post.
(sorry for revive didn’t realise this was 16 days old)
I think its fine because it is still related to that piece of code. The only time it is not acceptable is asking for how to make a lightsaber code on a question about doors.