PlayerBan Data Issue

So I made an anti-exploit and when you get banned you couldn’t join the game (it will keep kicking you), but for some reason when a banned player joins he/she doesn’t get kicked again.

Ban function

function banPlayer(player)
	local playerId = player.UserId
	
	local success, errormessage = pcall(function()
		banDataStore:SetAsync(playerId, true)
	end)
	
	if success then
		print(player.Name.. " has been permanently banned!")
	end
	
	player:Kick("You are banned for exploiting!")
end

Script for when they rejoin

local DataStoreService = game:GetService("DataStoreService")
local banDataStore = DataStoreService:GetDataStore("BannedPeople")

game.Players.PlayerAdded:Connect(function(plr)
	
	local playerId = plr.UserId
	
	local banned
	local success, errormessage = pcall(function()
		banned = banDataStore(playerId)
	end)
	
	if banned == true then
		plr:Kick("You are banned for exploiting!")
	end
end)

It successfully kick the player the first time, but they can rejoin…

Perhaps go through the datastore and kick the person if it matches up?

Yeah i did it i just updated the post

Have u used getasync? and try making a isbanned value

if the isbanned value == true then plr:Kick()

Or u could say in a local script blah blah blah remoteevent:fireserver()

I dont know, its should work because whenever someone joins it checks on the datastore if they’re banned if so it kicks them

Then u could say in a server script game.replicatedstorage.remoteevent.OnserverEvent:Connect(function(PlrToBan)
if IsBannedValue == true then
Plr[PlrToBan]:Kick()
end
end)

Try this - in your case, pcall calls for either success or errormessage.

if success then
		plr:Kick("You are banned for exploiting!")
	end

Ok i will try it. Brb just a sec

Do u want to use value’s? if so u could do IsBanned.Value = DataStore:GetAsync(player.UserId)

Still doesn’t work. I don’t know why

Well, have u tried using value’s like an anti-exploit value and whenever for example a players walkspeed is changed to 60 then it will be true and in the script u could say if anti-exploit value == true then plr:Kick()
but before that u could say anti-exploit.Value = DataStore:GetAsync(player.UserId)

banned = banDataStore(playerId)

Should be

banned = banDataStore:GetAsync(player.UserId)

1 Like

The anti exploit works it just that the player isn’t keeping banned. Btw you can’t make an antiexploit for walkspeed i think

It was a example but okay… have u tried doing what i said?

It works now, I didn’t see this thanks so much!

1 Like