Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Remote Function Value cast to Object?

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

6 comments

0

Are you sure you're invoking the client with the actual Player object? or you're invoking with the name as the variable seems to represent

0

also why did you write nil in the 2nd argument

0

Because it says in the API that the 2nd argument is a required Tuple so since I didn't have one I just put nil

0

can the server even access the player mouse?

0

Nope, you need to use a LocalScript in StarterGui because Player:GetMouse() only works in LocalScripts

0

when you're not going to need the Tuple just don't write the 2nd argument as it is the same as if you wrote nil

1 answer

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

2 comments

0

Yeah, I completely forgot that the first argument type was Player. Double thumbs up for inferring correctly and solving my problem!

0

Please accept my answer if it's right c:

This discussion is preserved as it was. New answers, comments, and votes are closed.