The script I showed is pretty bad. Generally when making anti-cheats like this, you want to do things on the server. A simple anti-fly should work for smthn like this.
If you still want to prevent this kind of exploit on the client, the essence of the idea was that when x-holding, the client stops certain ‘processes’. A MUCH better way to do this would be to have a client-side only script that checks if the game is not rendering any frames for a certain duration of time.
local RunService = game:GetService('RunService')
local players = game:GetService('Players')
local player = players.LocalPlayer
local MAX_INACTIVE_TIME = 3 --will kick player when x-holding for longer than 3 seconds.
if deltaTime > MAX_INACTIVE_TIME then
player:Kick('X-Holding for '..tostring(deltaTime)..' seconds.')
connection = RunService.RenderStepped:Connect(onStep)
RenderStepped gives deltaTime, which is the amount of seconds that have passed since the last frame.
Keep in mind, this will also affect players with low framerates. You might want to make a less violent punishment than kicking, or give the player more chances. An example of a less violent punishment is simply sending them to the ground, or respawning them.
X-Holding is just a simpler way to ‘fly’. So you can assume most people who attempt it are not exploiters and wouldn’t be able to bypass this script. If you want to totally prevent flying and x-holding, use a server script.