I'm having a little trouble using RemoteFunction. I am trying to have a LocalScript in StarterGUI return something to a Script in a Part in Workspace. This is an excerpt from the Script:
1 | local gcm = game.ReplicatedStorage:WaitForChild( "getClientMouse" ) |
2 | local mouse = gcm:InvokeClient(playerName, nil ) |
It keeps giving me an error with the second line, saying 'unable to cast value to Object' I'm not sure why this is In case you need my LocalScript code
1 | remotefunction = game.ReplicatedStorage:WaitForChild( "getClientMouse" ) |
2 |
3 | function remotefunction.OnClientInvoke(playerName) |
4 | print (game.Players.LocalPlayer:GetMouse().ClassName) |
5 | return game.Players.LocalPlayer:GetMouse() |
6 | end |
you are invoking the client with a string if I'm right (as it says playerName...) if you don't have the player reference, try this:
1 | -- Server Script |
2 | local gcm = game.ReplicatedStorage:WaitForChild( "getClientMouse" ) |
3 | local player = game:GetService( "Players" ):FindFirstChild(playerName) |
4 | local mouse = gcm:InvokeClient(player) |
also the function in the localscripts the parameter (playerName) you specified is actually nil as when you invoke to a client you dont get the player since it's a request sent by the server and you don't need the player parameter when you're actually the player