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

Why does this cause "Unable to cast value to object" into output?

Asked by 5 years ago

I'm making a shop where a player can click on a mannequin's clothes and get information on the clothes, buy the product, or add it to a cart to try on. I set up a RemoteFunction called OpenItemCard in the ReplicatedStorage and whenever the player clicks on clothes, I want the script to invoke OpenitemCard to send information from the mannequin to the client. Whenever I click on the mannequin all that shows up on output is "Unable to cast value to Object" and "Script 'Workspace.Mannequin.ShirtPurchase.ClickDetector.WhenClicked', Line 5" What do?

server side script (line 5 mentioned above is line 5 below)

Adornee = script.Parent.Parent.Parent.AdorneeAnchor
ShirtID = string.sub(script.Parent.Parent.Parent.Body.Shirt.ShirtTemplate, 14)
script.Parent.MouseClick:connect(function()
    print("Click Detected")
    game.ReplicatedStorage.OpenItemCard:InvokeClient(ShirtID, nil, Adornee)
    print("Client Invoked")
end)

here's the remote function being called on the client side

OpenItemCard = game.ReplicatedStorage:WaitForChild("OpenItemCard")

function OpenItemCard.OnClientInvoke(player,ShirtID,PantsID,Body)

1 answer

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

Line 3 of your remote function. Client side. Remove the player parameter. Make line 3 look like this:

function OpenItemCard.OnClientInvoke(ShirtID, PantsID, Body)

On line 3 of your server script, make :connect to :Connect.

script.Parent.MouseClick:Connect(function(player)

Add the player parameter to the event. Make line 5 look like this:

OpenItemCard:InvokeClient(player, ShirtID, nil, Adornee)

Invoke the specified client. It’s always the first argument to InvokeClient, but not a parameter in OnClientInvoke.

Edit: If you added a player parameter for OnClientInvoke, your InvokeClient would look like this:

OpenItemCard:InvokeClient(player, player, ShirtID, nil, Adornee) 
-- two player arguments. not cool.
0
how would I be able to call the player in OnClientInvoke if it isn't a parameter? Should I just use the name of the argument set back at InvokeClient? BronzedMocha 60 — 5y
0
Because this is the player you’re invoking the remote function to. In OnServerInvoke, THATS where you need the player parameter, but it doesnt get passed as an argument This is client invocation were dealing with. User#19524 175 — 5y
0
Thank you BronzedMocha 60 — 5y
Ad

Answer this question