How can I make my raycasts *pinpoint* accurate while being exploit-proof?

Right now, my raycasts are a simple;
player clicks -> remote event fired -> raycast created
because that is super duper exploit proof!

the thing is, there is a slight “inaccuracy” with the raycasts, and i wanted to ask how i can make my raycasts pinpoint accurate whilst being exploit-proof, as the title suggests

Perform the raycast on the client, then verify the client’s information on the server

1 Like

From what i believe, there isnt a possible way to get thr player’s mouse without using a remote event that is exploitable. I have no idea what you plan to do with those exploits but if, for example, it was a FPS game then go from thr head to the area where the mouse clicked.

I haven’t been able to write a perfect solution of my own, but I’ve been using this article by Roblox as my tutorial for server-side raycast verification.

If you just want somewhere to start, this is one way you can implement a verification system:
You cast a ray locally when needed (like when a user is shooting a gun) and do all your client visuals locally. You then send a remote event into the server with relevant data like your RaycastResult, the Ray’s Origin and the Raycast Parameters as the parameters. You then cast a ray on the server and see if it hit what the local ray hit.

In short form:
player clicks -> cast ray locally -> remote event fired -> cast identical ray on the server -> compare and verify

1 Like

verify how?

do i check if the source is equal to the player or something?

won’t this still be a bit inaccurate? so it’ll always be incorrect? unless i’m a bit stupid (i am)

There will be latency, but as long as you send identical data, you should get near identical results (If the player doesn’t hit the same target, you probably shouldn’t act upon the ray). The method I’ve shown may not be the most accurate in terms of predicting where the target will go and correctly scan accordingly, but this method is the most simple form of server-side raycasting and should prevent client exploits that involve manipulating the environment locally to guarantee hits on a target.

as far as I know, raycasting is literally perfectly accurate, at least down to floating point rounding errors(~15 decimal places)

1 Like