Weird problem with Raycast detection on the client

  1. What do you want to achieve? - I’m making a simple combat system where each time the player throws a punch, a ray will be cast in front of the player. If the ray touches a target, the player will automatically move to the target.

  1. What is the issue? - My raycast detection is done on the client and I make the player move on the server. Problem is, the detection doesn’t always register when I shoot out the rays too fast like this. What I found strange was that, when I transferred the raycasting to a server script, there was no issue, so I assume it’s a problem caused by the client.

Local Script

if raycastResults then
	if raycastResults.Instance.Parent:FindFirstChild('Humanoid') then

		local targetPosition = raycastResults.Position
		moveEvent:FireServer(targetPosition)

	end
end
  1. What solutions have you tried so far? I haven’t found a post relating to this issue specifically but I have tested the issue by printing whenever the ray hits something.

I shortened the script but it seems to be the source of the problem.

Any help would be appreciated!

There shouldn’t be any issue with client-sided raycasting. It may have to do something with lag or the raycast filtering if it’s only sometimes that it doesn’t register.

1 Like

I restarted my studio and the problem was resolved. It was pretty strange, but thanks for the feedback.