Server Sided Ray Casting?

I am trying to make a server-sided pistol where when the player clicks with the gun it cast a ray but the problem I have is I want the ray to cast to the player’s mouse.hit.p but I’m trying to do it server sided because if I send over what it from the client then an exploiter only has to fire an event and change the parameter to hit anything on the map. Any Solutions

So how can I get Mouse.Hit.p to the server without exploiters just changing the fired event parameter.

script.Parent.Activated:Connect(function()
 	local Raycast = Ray.new(script.Parent.SmokePart.CFrame.p, Mouse.Hit.p -script.Parent.Handle.CFrame.p * 500)
	local Hit, Position = game.Workspace:FindPartOnRayWithIgnoreList(Raycast, {script.Parent, script.Parent.SmokePart}, false, true)
	print(Hit)
end)
1 Like

Sorry to say, but there is no safe way to get Mouse input from client to server, you’ll always have the probability of it being altered, you just need to do server sided sanity checking.

1 Like

Although this doesn’t answer your question, a quick note is to remember when raycasting to convert the:

Mouse.Hit.p - script.Parent.Handle.CFrame.p

to

(Mouse.Hit.p - script.Parent.Handle.CFrame.p).unit

and only then can you multiply it. The “.unit” makes the vector only “1” long without changing its direction; the *500 makes it 500 long while also preserving it’s direction.

I hope you find your solution!

1 Like

do you mind explaining sanity checking

I think what he means is basically checking if where the mouse is pointing is possible (sane). For example, checking if the mouse location fits around where the head is pointing or things like that. I believe he can explain it better.

1 Like

By this I mean, you have to validate if the cast is possible, as mentioned above, testing to see if the angle is possible is a valid way of doing this, as-well as making sure there isn’t any obstructions between the character and said mouse position, because although a client could remove objects on their end the same can’t be said for the server so you simply use a raycast to check for that.

3 Likes

I got you thanks for the help .

1 Like