A simple review and feedback to my super simple anti cheat methods

Some codes I made that detect client-side scripts Fly Hacks , Speed, Executing from suspecious, strings Would be useful to some games also anyway to beautify them?

Anti Speed

-- Define the maximum allowed speed
local MAX_SPEED = 16 -- Change this to the maximum allowed speed in your game

-- Connect a function to the player's characterAdded event
game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
        -- Connect a function to the character's move event
        character.Humanoid.Move:Connect(function(movementDirection)
            -- Calculate the player's current speed
            local currentSpeed = movementDirection.magnitude
            
            -- Check if the player is moving too fast
            if currentSpeed > MAX_SPEED then
                -- Kick the player
                player:Kick("You were detected using a speed hack!")
            end
        end)
    end)
end)

Anti Execute from suspecious strings / Debugs

-- Define a list of suspicious functions to search for in the player's scripts
local suspiciousFunctions = {
    "loadstring",
    "assert",
    "pcall",
    "xpcall",
    "debug",
    "setfenv",
    "getfenv",
    "require",
    "dofile",
    "loadfile"
}

-- Define a function to scan the player's scripts for suspicious functions
function checkScripts(player)
    for _, script in ipairs(player.Character:GetDescendants()) do
        if script:IsA("LuaSourceContainer") then
            local source = script.Source
            
            -- Check if the script contains any suspicious functions
            for _, funcName in ipairs(suspiciousFunctions) do
                if source:find(funcName) then
                    -- Kick the player
                    player:Kick("Cheating is not allowed in this game!")
                end
            end
        end
    end
end

-- Connect a function to the player's characterAdded event
game.Players.PlayerAdded:Connect(function(player)
    -- Periodically scan the player's scripts for suspicious functions
    while player.Parent do
        checkScripts(player)
        wait(1)
    end
end)

Whitelist method (More complicated)

-- Define a list of whitelisted script names
local whitelist = {
    "MainScript",
    "UI",
    "Sound",
}

-- Connect a function to the game's childAdded event
game.DescendantAdded:Connect(function(descendant)
    -- Check if the descendant is a script
    if descendant:IsA("Script") then
        -- Check if the script's name is not whitelisted
        if not table.find(whitelist, descendant.Name) then
            -- Log the user's information and flag the script for review or removal
            local player = game.Players:GetPlayerFromCharacter(descendant.Parent)
            if player then
                print("User " .. player.Name .. " executed suspicious script " .. descendant.Name)
                -- TODO: Flag the script for review or removal
            end
        end
    end
end)

3 Likes

For the antispeed, I would recommend doing it on the server since you can do magnitude checks there. For the anti execute, they can hide there scripts in the player as well, so try checking there.
For the whitelisting, it may remove items added by other client scripts, which wouldn’t be good… You could add a check, like a bindable event asking if it was made by another script, or a certain attribute.

A lot of people will tell you that this script is not good because exploiters can just delete it, but it can protect your game from exploiters using bad executers/doesnt know how to code

1 Like

There is no way to detect if a script is being executed by an executor since exploits in general bypass Roblox’s Bytecode and goes to the Roblox Deserialiser which executes the malicious code.

To also further add to my point, it is very difficult to secure the client.

You should refer to the article linked.

1 Like

For the anti execute you should add _G and getgenv() to it as many exploiters use them for variables.

1 Like