Code help Is this outdated?

So I have been trying to make currency purchasing in my game the prompt if player clicks button is supposed to go up to buy dev product but the output says player needs to be player or something like that what wrong with the code???

MPS = game:GetService(“MarketplaceService”)

id = 1068491731 – replace with your ID

local player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:connect(function()

MPS:PromptProductPurchase(player, id)

end)

1 Like

The player should be the player’s id.

MPS = game:GetService(“MarketplaceService”)

id = 1068491731 – replace with your ID

local player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:connect(function()

MPS:PromptProductPurchase(player.UserId, id)

end)
1 Like

It isn’t the player ID, its the player Instance. There’s an example of this seen here. The only issue with this code is the indentation and how it’s laid out.

--//Services
local Players = game:GetService("Players")
local MarketplaceService = game:GetService("MarketplaceService")

--//Variables
local LocalPlayer = Players.LocalPlayer
local Button = script.Parent

--//Controls
local ProductID = 1068491731

--//Functions
Button.MouseButton1Click:Connect(function()
	MarketplaceService:PromptProductPurchase(LocalPlayer, ProductID)
end)

Yes, for that method. I think the problem is that the id is a gamepass id and should be prompted by :PromptGamePassPurchase() MarketplaceService:UserOwnsGamePassAsync

MPS = game:GetService(“MarketplaceService”)

id = 1068491731 – replace with your ID

local player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:connect(function()

MPS:PromptGamePassPurchase(player.UserId, id)

end)

This code looks outdated, but it still works.

Edit: Just noticed that I was checking for the gamepass, not prompting the player it.

They are using developer products, not gamepasses as said in the main post:

1 Like

How I would’ve written it, minus the comments.

1 Like

Yea, I just add those to keep some sort of organization.

Just noticed a minor detail, you should capitalise the first c in “connect”.


this is what i get in output

Oops, thanks for telling me.

30

Try my script:

--//Services
local Players = game:GetService("Players")
local MarketplaceService = game:GetService("MarketplaceService")

--//Variables
local LocalPlayer = Players.LocalPlayer
local Button = script.Parent

--//Controls
local ProductID = 1068491731

--//Functions
Button.MouseButton1Click:Connect(function()
	MarketplaceService:PromptProductPurchase(LocalPlayer, ProductID)
end)

You’re using Script when you should use LocalScript

1 Like

Use a localscript instead.

30