Get the mouse hit in server?

Hey guys, I’m creating a gun script and i have a question.

How do i send Mouse.Hit.P over to the server?

I don’t know how to make the server receive that information,. Ive used RemoteEvents and they fire and everything i just cant receive that information. Thanks :slight_smile:

1 Like

I reckon that you can use a RemoteFunction to retrieve Mouse.Hit.P.


-- Client
RemoteFunction.OnClientInvoke = function()
    return Mouse.Hit.P
end

-- Server
local hitPosition = RemoteFunction:InvokeClient(player)

However, I’d suggest invoking from client and let the server do the handling with rays and stuff. This will avoid the painful server lag(laggy cannons).

1 Like

Yeah but how do i access that Mouse.Hit.p from the server? i cant just type Mouse.Hit.P in the script, that doesn’t work for me.

As written in the example above. The position is passed in the invocation, hence hitPosition and InvokeClient.

2 Likes

No please. A client can overwrite OnClientInvoke and permanently hang the server. RemoteEvents or sandboxing OnClientInvoke calls in pseudothreads are the only appropriate method here.

I forgot the example for the latter, I’ll get back to you if I find it.

2 Likes