i'm not sure if this is a thing or not is there a way to ban somebody when they leave?
✓ ANSWER ACCEPTED
Ban somebody when they leave the game?
2 answers
✓ Accepted answer
You can get their UserId and save it to a DataStore. By using this, when they rejoin, they will be kicked.
local datastore = game:GetService("DataStoreService"):GetDataStore("Ban")
game.Players.PlayersAdded:Connect(function(plr)
local success,err = pcall(function()
return datastore:GetAsync(plr.UserId)
end)
if success then
plr:Kick("Banned.")
else
datastore:SetAsync(plr.UserId,"Banned")
end
end)
1 comment
0
Thanks!
If you want to ban someone when they leave the game, use PlayerRemoving. If you are confused, try this.
local Players = game:GetService("Players")
local dds = game:GetService("DataStoreService")
local banDataStore = dds:GetDataStore("BanData")
Players.PlayerRemoving:Connect(function(plr)
local banned
local success, err = pcall(function()
banned = banDataStore:SetAsync(plr.UserId, true)
end)
if success then
plr:Kick("You are banned from the game.")
else
print(err)
end
end)
Players.PlayerAdded:Connect(function(plr)
if banDataStore:GetAsync(plr.UserId) then
plr:Kick("You are banned from the game.")
end
end)
This discussion is preserved as it was. New answers, comments, and votes are closed.

2 comments
Yes.
I just answered it!