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 ( Doesn't work )
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)