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

I am trying to make a simple shop gui but cant use the dev products. Ideas?

I am trying to make a ui that you can buy coins but for some reason when I call the marketplaceservice prompt purchase event I get the error "unable to cast value to object". Any ideas?

for _,v in pairs(PlayerGui:WaitForChild("BuyCoinsUI").Main.PackageFrame:GetChildren()) do
	if v:IsA("ImageLabel") then
		v.PurchaseCoins.MouseButton1Click:Connect(function()
			PlayClickAudio()
			if v.Name == "BasicCuberPackage" then
				print("basic bought")
				MarketplaceService:PromptProductPurchase(player.UserId, 975968181)
			elseif v.Name == "AdvancedCuberPackage" then
				print("advanced bought")
				MarketplaceService:PromptProductPurchase(player.UserId, 976009690)
			elseif v.Name == "LegendaryCuberPackage" then
				print("legendary bought")
				MarketplaceService:PromptProductPurchase(player.UserId, 976010896)
			end
		end)
	end
end

1 answer

I'm going to make the assumption that you have all your variables well-defined and that your player variable is not set as the character but as the player itself.

According to the Roblox Documentation, you need to refer to the player itself - not their UserID. You can find more about that here.

Your script should look like what I have below.

for _,v in pairs(PlayerGui:WaitForChild("BuyCoinsUI").Main.PackageFrame:GetChildren()) do
    if v:IsA("ImageLabel") then
        v.PurchaseCoins.MouseButton1Click:Connect(function()
            PlayClickAudio()
            if v.Name == "BasicCuberPackage" then
                print("basic bought")
                MarketplaceService:PromptProductPurchase(player, 975968181)
            elseif v.Name == "AdvancedCuberPackage" then
                print("advanced bought")
                MarketplaceService:PromptProductPurchase(player, 976009690)
            elseif v.Name == "LegendaryCuberPackage" then
                print("legendary bought")
                MarketplaceService:PromptProductPurchase(player, 976010896)
            end
        end)
    end
end

If this helps, consider accepting this answer. If not, comment below and I'll help you out further.

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