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

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

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

✓ Accepted answer

To use InvokeClient your first argument must be the player(client) you are invoking. In your case I think you want to fire the open card function for the player that clicked so do this.

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

2 comments

0

It worked! But now in output it says "Unable to cast Instance to int64" what does that mean?

0

Can you tell me what line the error is on?

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