[HELP] Unable to cast value to object

I am having a problem where I am trying to promp a developer product purchase, the thing is, when the button is clicked it brings up the error; “Unable to cast value to object”.

local productId =  script.Parent.Value.Value
local player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:connect(function() 
 	game:GetService("MarketplaceService"):PromptProductPurchase(player.UserId, productId)
end)

If you know a fix I would be glad to hear it!
Thank you and have a great rest of your day.

  • Keegan (C6T9)
1 Like

PromptPurchase methods take a player, not a user ID. Just remove the .UserId portion. Also as a side note :connect is deprecated so you should switch to :Connect instead.

1 Like

game:GetService("MarketplaceService"):PromptProductPurchase(player.UserId, productId) takes the Player object, not the Player ID.

1 Like

Thank you, I meant to put a capitalized C but I guess I mistyped. But thank you very much for the help on this, for some reason a lot of people I had asked didn’t know the fix. Thank you!