Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Ban somebody when they leave the game?

i'm not sure if this is a thing or not is there a way to ban somebody when they leave?

2 comments

1

Yes.

0

I just answered it!

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.