My current script has itself invoking a RemoteFunction in the ReplicatedServer. A LocalScript then watching the RemoteFunction will use "GetMouse", using the "player" variable that is in the invoke. However, it says that "plr" is a nil value. Can somebody please help?
In the Script:
function gitMouse(plr) -- This is defined earlier as the player local remoteGetMouse = game.ReplicatedStorage:WaitForChild("GetMouse") local mouse = remoteGetMouse:InvokeClient(plr) return mouse end
In the LocalScript (Which is the receiver of the Invoke)
function remoteGetMouse.OnClientInvoke(plr) return plr:GetMouse() end
:InvokeClient(plr)
will invoke the client plr
, but that is not passed as a parameter to the client. If you want it to pass plr
to the client, try :InvokeClient(plr, plr)
When you Invoke the client, plr will not be passed as a parameter, it Invokes the RemoteFunction on that code.
Therefore your code will not work, because "plr" doesn't exist in the local script. You'll need to locate the player again.
function remoteGetMouse.OnClientInvoke() plr = game.Players.LocalPlayer return plr:GetMouse() end
EDIT: As Narrev said, to pass the player you'll need to write ":InvokeClient(plr,plr)" Then your code will work without my adjustments (Damn you Narrev writing an answer just a few seconds faster than me! xD)
MD