MarketplaceService Giving Me Grief

So I’m making a character customization UI, and one of the functions is as follows:

local PHCPassID = 8098194

HairColorEvent.OnServerEvent:Connect(function(Player, value)
	local HasPHCPass = MarketplaceService:UserOwnsGamePassAsync(Player.UserId, PHCPassID)
	local char = Player.Character
	local HairPart = char.Head.Hair:GetChildren()
	for _, part in pairs(HairPart) do
		if value == "01PHC" then
			if HasPHCPass then
				part.BrickColor = BrickColor.new("Really red")
			else
				MarketplaceService:PromptGamePassPurchase(Player.UserId, PHCPassID)
			end
		end
	end
end)

The purpose of this is to change the player’s hair color to "Really red"

if they own the gamepass. However when I attempt to click the button, the DevLog gives me this:
e05042d64caaa02d9490b9e1307371f7
(Apologies if it’s hard to read, but it says 00:29:21 -- Unable to cast value to Object). I tried replacing the “Player” in MarketplaceService:PromptGamePassPurchase(game.Players.LocalPlayer.UserId, PHCPassID) to no avail, as this is a regular script in ServerScriptService and LocalPlayer will not work. Anyone know how to fix this?

:Prompt methods take a player instance to prompt, not their user id. You might be confusing this with :UserOwnsGamePassAsync. There is a reason User is in there.

MarketplaceService:PromptGamePassPurchase(Player, PHCPassID)

This is exactly why you don’t post screenshots of output or of your code.

Agreed. @BIueMalibu, next time, copy & paste the error message from the output, not DevLog, and the line it’s referring to.

It didnt refer to any line in particular, that was the entire message. But in the future I will, thanks

So you’re saying I should remove the PromptGamePassPurchase entirely? I dont quite understand what you’re saying

It means remove the .UserId part from Player when you use PromptGamePassPurchase. Refer to documentation for more information. You need to pass a player, not their UserId. The fix was already provided for you in incapaxx’s post, just change the code as needed.

- MarketplaceService:PromptGamePassPurchase(Player.UserId, PHCPassID)
+ MarketplaceService:PromptGamePassPurchase(Player, PHCPassID)

Works, thank you very much.
30characterlimit

Wait, how did you do the green/red highlight thing? Just wondering :thinking:

Something to DM me for. I used diff syntax for my codeblock.

```diff
+ Plus signifies an addition
- Minus signifies a removal
```

1 Like