So, I'm trying to make a ban script, however, I want it to be secure from exploiters. So what I tried doing is making the server CREATE a bool value inside the player called "Banned", and then mark it as true and then kick the player, saving the banned value with it. However, when I tried it on my friends' alt (he let me) it only kicked him, but he was still able to rejoin. I need help, and it would be appreciated.

The Script:

local allowedAdmins = {74518383, 72372728}
local dataStoreService = game:GetService("DataStoreService"):GetDataStore("BanList")

game.Players.PlayerAdded:Connect(function(player)
	local success, notSuccess = pcall(function()
		isBanned = dataStoreService:GetAsync(player.UserId.."-banned")
	end)
	
	local banned = player:FindFirstChild("Banned")
	
	if success then
		banned.Value = isBanned
	else
		print("Error")
		warn(notSuccess)
	end
	
	if player:WaitForChild("Banned").Value then
		player:Kick("You are banned. You had your chance. Should have followed the rules.")
	end
	
	player.Chatted:Connect(function(message, recipient)
		if recipient then return end
		if not isAllowedAdmin(player) then return end
		
		if message:sub(1, 5) == "/ban " then
			local target = game.Players:FindFirstChild(message:sub(6))
			
			if target then
				local banned = Instance.new("BoolValue", target)
				banned.Name = "Banned"
				
				target:WaitForChild("Banned").Value = true
				print("Player Banned")
				target:Kick("You have been banned.")
			end
		end
	end)
end)

game.Players.PlayerRemoving:Connect(function(player)
	
	if player:FindFirstChild("Banned") then
		local success, notSuccess = pcall(function()
			dataStoreService:SetAsync(player.UserId.."-banned", player.Banned.Value)
		end)
		
		if success then
			print("Success")
		end
		
		if notSuccess then
			print("Error saving banned value")
			warn(notSuccess)
		end
	end
end)

function isAllowedAdmin(player) 
	for i = 1, #allowedAdmins do
		if player.UserId == allowedAdmins[i] then
			return true
		end
	end
	
	return false
end

6 comments

0

Ok I dont know a fix but you can install this plug, https://www.roblox.com/library/4919389349/Anti-Virus-1M-SALES , it says it will 100% block exploiters and virus's/injections in your game.

0

i think you need to use data stores

0

check in the data store when ever a player joins the game if he is banned if he is kick him

0

@MrMeeper9 we aren't saying nothing about hackers, just a ban system

0

@torchmaster101 is there a "Banned" value being created inside the player?

0

Technically, a ban value gets created in the player when an admin says "/ban (player)"