Hey, I’m working on an admin script. I need to be able to “serverban” players, though datastores save data to all servers.
I have looked over the DevForum and internet, I also tried multiple other things and haven’t really gotten anywhere at that.
How would I do this?
You can have a table “cache” the player UserId’s who aren’t allowed in that server instead of saving it to a datastore. So an example of this might be this:
local Players = game:GetService("Players")
local BannedServerPlayers = {}
Players.PlayerAdded:Connect(function(player)
if table.find(BannedServerPlayers, player.UserId) then
player:Kick()
end
end)
1 Like
If you just want it for the server only, you could just reference a table of Banned Players without using any DataStores
local ServerBanned = {}
local Admins = {"Evanthegr8t1"}
game.Players.PlayerAdded:Connect(function(Player)
if table.find(ServerBanned, Player.Name) then
Player:Kick("You have been banned from this server >:(")
end
if table.find(Admins, Player.Name) then
Player.Chatted:Connect(function(Message)
for _, Target in pairs(game.Players:GetPlayers()) do
if Message == "/serverban "..Target.Name then
table.insert(ServerBanned, Target.Name)
Target:Kick("You have been banned from this server >:( Reason: You made the creator angery")
end
end
end)
end
end)
3 Likes
Ah, I see. I guess it would involve tables thanks for that. Oh, and also you didn’t need to write a whole example script, you could have just said what BuilderBob had said first. (though he edited his post.) as I had forgot about using table.Insert for server-only problems. But thanks anyways.
I was literally on Studio to write that haha so it’s not really a big deal
Yeah, there’s a whole lot of table functions to know about Do look at the API Reference for more info
Yeah, I already did. I was just too focused on DataStores to pay attention to tables.
(Also, why in your example script does it use UserNames instead of UserID’s? )
Just a habit I use really, I don’t think it’d really matter anyways since you’re only server banning the “Player” (Plus I use it for more easier use lol, but of course if you want more security then UserId
’s are available)
The chances of that Player changing his name while banned is really slim though
Yes, but what if one of your admins change their name .
Again, I just gave an example
You can change it to UserId
’s if you want
Yeah, I was just questioning the use of UserNames in that script as I rather UserID’s by a longshot. Sorry, have a good day.
1 Like