LocalPlayer Purchase Prompt Error (Fixed)

Hey all!! I am trying to make a hair combo game with a GUI that prompts a player to buy the given hair/hat. Here’s the prompt code:

local MarketplaceService = game:GetService("MarketplaceService")

local id = script.Parent.Parent.ID.Value

script.Parent.MouseButton1Down:Connect(function ()
	MarketplaceService:PromptProductPurchase(game.Players.LocalPlayer, id)
end)

I keep getting an error saying “MarketplaceService:PromptProductPurchase() player should be of type Player” and I’m really confused. LocalPlayer is a type of player, right? Can someone help?

Not sure why, btw just going to point out though if you are trying to get your players to purchase a hair/hat from the catalog you should be using MarketplaceService | Roblox Creator Documentation Instead of PromptProductPurchase which is inteded to be used for developer products

Thank you for pointing that out, I fixed it.

Why does this code error? Im using this code and it runs fine
https://gyazo.com/af3dd11703209e0934a9d9b493d78cd0

local MarketplaceService = game:GetService("MarketplaceService")
script.Parent.MouseButton1Down:Connect(function ()
	MarketplaceService:PromptPurchase(game.Players.LocalPlayer, 6202091443)
end)

Did you make sure its a localscript?

Ohhh, it’s not a local script. I’ll switch it and see if that works.

:man_facepalming: LocalPlayer is intended to be used by localscripts to get the player that is running the code! Dont use it for regular scripts they’re obviously run by the server.

Ohh makes sense. Thank you so much!!

You should also use a server script with a remote event and a local script. Otherwise, hackers can bypass it.
Take a look at the example here

This is not a concern. Who cares if hackers buy other catalog items through their game? It just gives em more commission!