MarketplaceService:PromptProductPurchase() player should be of type Player

Hello! This is my script:

--variables--

local id = 1823654835 -- Paste here your ID. 

script.Parent.MouseButton1Click:Connect(function()
	print("You clicked!") -- It's just for a test.
	game:GetService("MarketplaceService"):PromptProductPurchase(game.Players.player,id)
	print("Donation succeed") -- It's just for a test.
end)

Can somebody help how to fix this issue?

isn’t it supposed to be game.Players.LocalPlayer ?

EDIT : ( I can’t test if game.Players.player can work since I’m on phone )

1 Like

I also tried this variant but it didn’t help (to be honest it was the first version of this code)

This is what the message shows

1 Like

wait you’re trying to get the player from the server, switch to a local script otherwise you won’t be able to require game.Players.LocalPlayer

You should try this instead:

script.Parent.MouseButton1Click:Connect(function(player)
	print("You clicked!") -- It's just for a test.
	game:GetService("MarketplaceService"):PromptProductPurchase(player.UserId, -- put ID here)
	print("Donation succeed") -- It's just for a test.
end)

No, it won’t work also :frowning:

It says the same thing

is your script a server script or a local script?

local ProductId = productId

script.Parent.MouseButton1Click:Connect(function()
	game:GetService("MarketplaceService"):PromptProductPurchase(game.Players.LocalPlayer, ProductId)
end)


This should work, make sure you put this into a LocalScript instead of a server script since I can see that you’re using a server script.

1 Like

image
I put this script here and it doesn’t work either (productid, I switched to my id) and while I click on this button it won’t even print the commands I pasted.

Are there any output errors? (char limit)

I tried the script and local script to check if it works with local script or script.

Nope, I only have errors with music in other models, but there’s nothing else.

Well maybe try script.Parent.Parent.Parent.Parent you get the idea, the script is parented to a gui in playergui and the parent of the playergui is the player instance. Although game.Players.LocalPlayer should’ve worked maybe this will change something? There might be more parents to reach the player instance I can’t remember.


Okay, guys… This worked. Idk what I’ve done wrong before but now this is working. Thank you all so much!

I would say yay or congratulations but alot of my posts get flagged now. But then again this one might also get flagged, please don’t flag me mods.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.