Unable to cast value to object

I am making a thing to sell dev products on click but it doesn’t work and just gives me the error Unable to cast value to object.

local MPS = game:GetService("MarketplaceService")
local product = 1360886659

script.Parent.MouseButton1Down:Connect(function(player)
	MPS:PromptProductPurchase(player, product)
end)

What could be the problem?

1 Like

Try printing the player. The issue is that GuiButton.MouseButton1Down doesn’t pass the player as an argument to the callback/connected function. You can see what arguments each event passes on the wiki, e.g.

https://create.roblox.com/docs/reference/engine/classes/GuiButton#MouseButton1Down

Try this

local MPS = game:GetService("MarketplaceService")
local Player = game:GetService("Players").LocalPlayer

local product = 1360886659

script.Parent.MouseButton1Down:Connect(function()
	MPS:PromptProductPurchase(Player, product)
end)

As @ThanksRoBama GuiButton.MouseButton1Down does not pass the player, but you can use players.LocalPlayer to get the player