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:
(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.
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.