Help with anti-infinite jump!

Right now I’m currently developing an AntiCheat and I’m having issues with the anti-infinite jump script.

Basically, when the player presses the space bar a number of times before hitting the ground, a ray is cast from the player’s humanoid root part -100 studs on the Y-axis. If the hit part of the ray is 12 studs or farther from the character, it should kill them, like this;

Safe

The issue is though, that when the player isn’t infinite jumping and presses the space bar a bunch of times, it still kills them. I know this may seem like a hacky way to prevent anti-infinite jumping, but I haven’t seen any other ways that would be more reliable than this.

I think I’ve tracked down the issue to this portion of code (I won’t release the whole script as I don’t want people to just take my anti-cheat.) here it is -

if raycastResult then
		local hitPart = raycastResult.Instance

		local pos = characterP:FindFirstChild("HumanoidRootPart").Position
		local partpos = hitPart.Position -- where I believe the error is
		
		local distance = (pos - partpos).Magnitude
		print(distance)
		
		if distance > 12 then
			return false
		end
	end

I believe the issue is that when the ray hits the part, it gets the part’s CENTER position, not the position of where the ray hit the part.

This effect is especially apparent when jumping on a small brick compared to jumping on a big brick. On the small brick, you will almost always be close to its center. On the big brick, the center is most likely far away from you, and will therefore kill you.

I looked around a bit for how to get the position of where the ray hit the part, but I couldn’t find anything. I’m hoping that someone here would have an idea of what I could do in this situation.

2 Likes

I’m not entirely familiar with the new raycast system yet, but I think that RaycastResults return a Position value that corresponds to where the ray hit the part. Try replacing hitPart.Position with raycastResult.Position and see how it goes.

2 Likes

Thanks, I’ll try this and get back to you with what happens.

Edit: This actually worked! Thanks so much for the quick response, I’ll comment you in the anti-cheat! :wink:

2 Likes