Issues making a Ban Module for a client-sided/localscript anticheat

First post here, anyways…
I’ve been trying to make an Anticheat for my games, and making a module for a ban system. I’ve been having some issues with said module…
I had a friend help with it, but it still doesn’t work.

The said script/module:

local DataStoreService = game:GetService("DataStoreService")
local BanDS = DataStoreService:GetDataStore("SingularityBans")
local RepStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local CachedData = {}

Players.PlayerAdded:Connect(function(Plr)
	local Key = tostring("User_"..Plr.UserId)
	local Table

	local success, err = pcall(function()    
		Table = BanDS:GetAsync(Key) or {}
	end)

	if not Table.BanInfo then
		Table.BanInfo = {
			IsBanned = true;
			Reason = "No Reason";
		}
	end

	if success then
		CachedData[tostring(Plr.UserId)] = Table
		if Table.BanInfo.IsBanned then
			Plr:Kick(Table.BanInfo.Reason)
		end
	else
		warn("Error Detected In Singularity Ban Module!")
	end
end)

Players.PlayerRemoving:Connect(function(Plr)
	if CachedData[tostring(Plr.UserId)] then
		local success, err = pcall(function()
			BanDS:SetAsync(Plr.UserId, CachedData[tostring(Plr.UserId)])
		end)
		if err then
			warn(string.format("SetAsync Failed. (%s)", err))
		end
	end
end)

RepStorage.Remotes.Events.SingularityReciever.OnServerEvent:Connect(function(Plr:Player,Table:{IsBanned:boolean,Reason:string})
	CachedData[tostring(Plr.UserId)] = Table
	Plr:Kick(Table.Reason)
end)

Hello, I have never worked with a roblox ban system before but I will try to help you :slight_smile:

I’ll go through the script and provide some feedback and potential fixes:

Default Ban:

if not Table.BanInfo then
    Table.BanInfo = {
        IsBanned = true;
        Reason = "No Reason";
    }
end

SetAsync Key : In the PlayerRemoving event, you’re using the UserId directly as the key for SetAsync . However, when getting the data, you’re using the key format “User_” followed by the UserId . You should maintain consistency. Change:

BanDS:SetAsync(Plr.UserId, CachedData[tostring(Plr.UserId)])

In to :

BanDS:SetAsync("User_"..Plr.UserId, CachedData[tostring(Plr.UserId)])

Start error handing and debugging:

if err then, if not success then, print("Error"), print("Success") and so on

I’m not sure if I messed something up or not, but it still doesn’t seem to work…

if I were to make a localscript do

local BanEvent = ReplicatedStorage:WaitForChild("Remotes",30).Events.SingularityReciever
BanEvent:FireServer({true,"Reason here"})

Would that work…?