Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

RemoteFunction errors when the parameter is used?

Asked by
u_g 90
9 years ago

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

2 answers

Log in to vote
2
Answered by
Validark 1580 Snack Break Moderation Voter
9 years ago

: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)

Ad
Log in to vote
2
Answered by 9 years ago

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

Answer this question