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:
local gcm = game.ReplicatedStorage:WaitForChild("getClientMouse") 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
remotefunction = game.ReplicatedStorage:WaitForChild("getClientMouse") function remotefunction.OnClientInvoke(playerName) print(game.Players.LocalPlayer:GetMouse().ClassName) return game.Players.LocalPlayer:GetMouse() 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:
-- Server Script local gcm = game.ReplicatedStorage:WaitForChild("getClientMouse") local player = game:GetService("Players"):FindFirstChild(playerName) 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