How would I account for force-jumping off parts in this server sided Anti Infinite Jump script?

This is the exploit script that I am trying to patch:

local justSpawned = true
local lastJump = 	0
local minJumpDelay = 2

InfiniteJumpEnabled = false
game:GetService("UserInputService").JumpRequest:Connect(function()
	if InfiniteJumpEnabled then
		game:GetService"Players".LocalPlayer.Character:FindFirstChildOfClass'Humanoid':ChangeState("Jumping")
	end
end)

This is my server sided script to patch it. It detects when a player jumps, and kicks them if they jump again within 0.5 seconds later.

local LastJumps = {}
local Connections = {}
local MinJumpDelay = 0.5
local Players = game:GetService("Players")


Players.PlayerAdded:Connect(function(Player)
	local Id = Player.UserId
	Connections[Player.UserId] = Player.CharacterAdded:Connect(function(Char)
		LastJumps[Id] = 0
		local Humanoid = Char:WaitForChild("Humanoid", 2)
		if Humanoid then
			local StateConnection
			local DiedConnection
			local function OnStateChange(State)
				if State == Enum.HumanoidStateType.Jumping then
					print(tick() - LastJumps[Id])
					if LastJumps[Id] and ((tick() - LastJumps[Id]) < MinJumpDelay) then
						Player:Kick("InfJump")
						StateConnection:Disconnect()
						DiedConnection:Disconnect()
					end
					LastJumps[Id] = tick()
				end
				if State == Enum.HumanoidStateType.Landed or State == Enum.HumanoidStateType.Running or State == Enum.HumanoidStateType.RunningNoPhysics then
					print("Land/Run")
					if LastJumps[Id] then
						LastJumps[Id] = tick() - MinJumpDelay
					end
				end
			end
			StateConnection = Humanoid.StateChanged:Connect(OnStateChange)
			local function OnDied()
				StateConnection:Disconnect()
				DiedConnection:Disconnect()
			end
			DiedConnection = Humanoid.Died:Connect(OnDied)
		end
	end)
end)

Players.PlayerRemoving:Connect(function(Player)
	Connections[Player.UserId]:Disconnect()
end)

The issue is that when a player sort of bounces off a rotated part, it detects it as a jump (even if they didn’t click the space bar because I’m using GetState) and they get kicked. To help you imagine this scenario, look at this tree model:


And here’s what I mean by a bounce off:

Does anyone know of anything I could do to stop this behavior, or is this approach to an anti-infinite jump a lost cause?

Here’s my solution, basically I just added a check if the Humanoid’s FloorMaterial is Air with the MinJumpDelay check and if it is, kicks them. You may need to shorten the delay incase it still kicks but it fixes the problem your having.

Server Script
local LastJumps = {}
local Connections = {}
local MinJumpDelay = 0.5
local Players = game:GetService("Players")


Players.PlayerAdded:Connect(function(Player)
	local Id = Player.UserId
	Connections[Player.UserId] = Player.CharacterAdded:Connect(function(Char)
		LastJumps[Id] = 0
		local Humanoid = Char:WaitForChild("Humanoid", 2)
		if Humanoid then
			local StateConnection
			local DiedConnection
			local function OnStateChange(State)
				if State == Enum.HumanoidStateType.Jumping then
					print(tick() - LastJumps[Id])
					print(Humanoid.FloorMaterial)
					if LastJumps[Id] and ((tick() - LastJumps[Id]) < MinJumpDelay) and Humanoid.FloorMaterial == Enum.Material.Air then
						Player:Kick("InfJump")
						StateConnection:Disconnect()
						DiedConnection:Disconnect()
					end
					LastJumps[Id] = tick()
				end
				if State == Enum.HumanoidStateType.Landed or State == Enum.HumanoidStateType.Running or State == Enum.HumanoidStateType.RunningNoPhysics or State == Enum.HumanoidStateType.Climbing then
					print("Land/Run")
					if LastJumps[Id] then
						LastJumps[Id] = tick() - MinJumpDelay
					end
				end
			end
			StateConnection = Humanoid.StateChanged:Connect(OnStateChange)
			local function OnDied()
				StateConnection:Disconnect()
				DiedConnection:Disconnect()
			end
			DiedConnection = Humanoid.Died:Connect(OnDied)
		end
	end)
end)

Players.PlayerRemoving:Connect(function(Player)
	Connections[Player.UserId]:Disconnect()
end)
1 Like

I just noticed you also get kicked when jumping climb then jumping again, just add a State == Enum.HumanoidStateType.Climbing to the Land/Run area and it should be fixed.

1 Like