Stopping the freeze glitch

Hey everyone! I was wondering how I could stop the freeze glitch.
This is my current code, but I’m kind of confused on where to go from here

local Players = game:GetService("Players")

local MaxFreezeTime = 3

function CastRay(StartPos,Vector,Length,IgnoreList)
	local Hit,EndPos = workspace:FindPartOnRayWithIgnoreList(Ray.new(StartPos,Vector*Length),IgnoreList)
	return Hit,EndPos
end

function OnCharacterAdded(Player,Character)
	local Humanoid = Character:WaitForChild("Humanoid")
	local HRP = Character:WaitForChild("HumanoidRootPart")
	
	local LastVel = Vector3.new()
	local CurrentVel = Vector3.new()
	
	local TimeTaken = 0
	
	game:GetService("RunService").Stepped:Connect(function()
		if HRP and Humanoid then
			if LastVel == CurrentVel and not Humanoid.FloorMaterial then
				local Hit,EndPos = CastRay(HRP.Position,(HRP.CFrame.LookVector + Vector3.new(0,-3,0)).Unit,5,{HRP.Parent})
				
				local Distance = (Vector3.new(0,HRP.Position.Y,0) - Vector3.new(0,EndPos.Y,0)).Magnitude
				local TimeToFall = math.sqrt((2 * Distance)/workspace.Gravity)
				print(TimeToFall)
				
				if not Humanoid.FloorMaterial then
					if TimeTaken > TimeToFall then
						Player:Kick("Possible freeze glitch detected. If this is a mistake, please rejoin the game.")
					end
				end
			else
				LastVel = HRP.Velocity
			end
		end
	end)
end

Players.PlayerAdded:Connect(function(Player)
	if Player.Character then
		OnCharacterAdded(Player,Player.Character)
	end
	
	Player.CharacterAdded:Connect(function(Character)
		OnCharacterAdded(Player,Character)
	end)
end)

If anyone could help me complete the code, that would be great!

Also, any suggestions are welcome. If I’m going about this the wrong way, please let me know :slight_smile:

4 Likes

FindPartOnRayWithIgnoreList is Deprecated, in other words replaced with something more reliable

Sorry about that, I haven’t learned how to use workspace:Raycast() yet, but that isn’t the point of this topic. I’m looking how to prevent the freeze glitch, not for people to tell me not to use this raycasting method. I will be replacing it later, but it should work for now.

Wdym the “Freeze glitch”, are u trying to do an anti-exploit script?

try adding a task.wait()

	game:GetService("RunService").Stepped:Connect(function()
		if HRP and Humanoid then
			if LastVel == CurrentVel and not Humanoid.FloorMaterial then
				local Hit,EndPos = CastRay(HRP.Position,(HRP.CFrame.LookVector + Vector3.new(0,-3,0)).Unit,5,{HRP.Parent})
				
				local Distance = (Vector3.new(0,HRP.Position.Y,0) - Vector3.new(0,EndPos.Y,0)).Magnitude
				local TimeToFall = math.sqrt((2 * Distance)/workspace.Gravity)
				print(TimeToFall)
				
				if not Humanoid.FloorMaterial then
					if TimeTaken > TimeToFall then
						Player:Kick("Possible freeze glitch detected. If this is a mistake, please rejoin the game.")
					end
				end
				
				task.wait()
			else
				LastVel = HRP.Velocity
				task.wait()
			end
		end
	end)

Weird, But the Character freezes? Or does the game freeze?

The script isn’t yet complete. It will not work in this state. I’m asking for assistance in completing it.

Yeah, tabbing out isn’t your game’s glitch, it’s a Roblox glitch.

But I’m wondering if I can kick them for doing the glitch.

1 Like

Nah, you can’t. I think you can put them to the ground using an anti-cheat if you do detect them floating.

Or detect frames that we’re frozen in the client or server.

1 Like

Nah, you can’t. The server doesn’t freeze unlike the client. I don’t think it’s possible to detect if someone’s frames are frozen, since if you’re asking for it, they can give you whatever they want, like an invalid answer.

It uses ping. It detects if ping is too high, and if it is, you will get kicked. And the freeze glitch increases the ping. So, you can add a LocalScript or Script (I dont know how to make ping counter, sorry) that detects if player’s ping is higher that certain amount (somewhere around 800) and kicks the player.
Don’t really think it is the best solution, but I will inform you if I find a better way.

How I would fix this: kick the player if latency is to high. Its actually quite simple. If you want me to write you the code I can

id like that, thanks!

this is a pretty old topic though, how did you find it lol?

Through your profile because you helped me. Haha

lol. but yeah if you have any code for this, can you provide it? thanks

I am working on that right now. I’ll give you the code in a little bit, I have to get home and test it

You could use InvokeClient on a RemoteFunction, and count how long it takes for the client to return true or some number back. It’s not advised to use InvokeClient because exploiters get a bit of power. They can make the call hang forever, but you can still detect this as high latency.

its not letting me post my code for some reason oh well :confused:

i already have a ping counter system