Local 'mouse' is a nil value

Hello, I tried to make a remote function to call a Horse event but it’s saying that my local mouse is a nil value. What I did was call it through the function “script.Horse.OnServerEvent:Connect(function(player, mouse)” but for some reason it came off as nil. Does anyone know how to fix this?

Error

image

Remote Function

image

Where it's stated in the localscript

image

This is because the Mouse object is not replicated to the server. It only exists on the client. You should handle the input on the client and then call the relevant remote events with the required information.

5 Likes

In this case you’d send mouse.Target.Parent to the server instead of the mouse object itself. If you need to verify the mouse target, which is probably why you’re making this mistake, you need to find another way of making sure the player isn’t cheating.

Also, there’s another error in the making in the RemoteEvent listener. You cannot call RemoteFunction:InvokeServer() on the server – you should use a BindableFunction instead.

2 Likes

How would I use a BindableFunction?

You’d have it somewhere the server can access, and you’d just use it like a normal event.

BindableFunction:Invoke(Arguments)

BindableFunction.OnInvoke = function(Arguments)

end
2 Likes