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

Remote Function Value cast to Object?

Asked by 5 years ago

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
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 SulaymanArafat 230 — 5y
0
also why did you write nil in the 2nd argument SulaymanArafat 230 — 5y
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 fa_QURobloxXD 29 — 5y
0
can the server even access the player mouse? the8bitdude11 358 — 5y
View all comments (2 more)
0
Nope, you need to use a LocalScript in StarterGui because Player:GetMouse() only works in LocalScripts fa_QURobloxXD 29 — 5y
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 SulaymanArafat 230 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

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

0
Yeah, I completely forgot that the first argument type was Player. Double thumbs up for inferring correctly and solving my problem! fa_QURobloxXD 29 — 5y
0
Please accept my answer if it's right c: SulaymanArafat 230 — 5y
Ad

Answer this question