✓ Accepted answer
The code you have so far will successfully kick the player, but it will not ban them. To ban the player you need to save their UserId to a datastore. This can be done using the SetAsync() method of GlobalDatastore. Below is the code to save their UserId to the datastore.
local ds = game:GetService("DataStoreService"):GetDataStore("Bans")
ds:SetAsync(found.UserId, true)
This can be implemented into your current code like so:
elseif msg:lower():sub(1,4) == ";ban" then
local obj = msg:sub(6)
local found = game.Players:FindFirstChild(obj)
local ds = game:GetService("DataStoreService"):GetDataStore("Bans")
if found then
ds:SetAsync(found.UserId, true)
found:Kick("You have been banned!")
else
print(obj.." is not a player!"))
end
But this is not enough to to totally ban the player. To ban the player we're going to need a script that checks if a player is on the Bans datastore everytime a player joins. I recommend putting this script into ServerScriptService to prevent any client access. This script is below.
game:GetService("Players").PlayerAdded:Connect(function(plr)
local ds = game:GetService("DataStoreService"):GetDataStore("Bans")
if ds:GetAsync(plr.Userid) then
plr:Kick()
end
end)
Let me know if anything is wrong. If my answer helped you, make sure to mark it as correct!
4 comments
Thanks for replying. For some reason, when I try to test this on one of my alts, it says, "PLAYERNAME is not a player". Substitute PLAYNAME for my alts' name. Not sure why it is doing this.
https://gyazo.com/88fb4a621fc02e158affd571ba03f7a8 Picture
I got rid of the FindFirstChild thing, and it works fine. Thanks for telling me what I should do.
No problem.