i'm not sure if this is a thing or not is there a way to ban somebody when they leave?
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)
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)