Place this script under a GUI Button Object. It should be a LocalScript.
local MarketplaceService = game:GetService("MarketplaceService")
local player = game:GetService("Players").LocalPlayer
local GamepassId = 000000000
script.Parent.MouseButton1Click:Connect(function()
MarketplaceService:PromptGamePassPurchase(player, GamepassId)
end)
Your previous script has probably caused a lot of errors.
Message
I’m not sure if you can buy something using a Local Player but it should work.
If I am right, you probably want it to prompt purchase to the player who touches the specific part? Then you will have to get Player from the character & then prompt the purchase for that player.
So your script seems to be having the problem, because you want to Prompt For a Developer product purchase, so you need to be using PromptProductPurchase function of MarketPlaceService, and pass in the Player instance & product Id respectively
Well, I don’t really want to Spoon Feed you with all the code, but I have guided you with what needs to be Used for products that can be bought multiple times, which you want.
For example code can be like this
local ClickDetect = script.Parent:FindFirstChildOfClass("ClickDetector")
local ProductID = 000000 -- ID of your product is required
local MarketPlaceService = game:GetService("MarketplaceService")
ClickDetect.MouseClick:Connect(function(player)
MarketPlaceService:PromptProductPurchase(player, ProductID)
end)
Then if you want to check if someone has bought this, you would want to use ProcessReceipts as told by @Trizxistan earlier in the thread
It would be best if you didn’t try to get Player from the MouseButton1Click event. You can make a different variable Player and remove the argument Player from that event. To get the Player via gui (not with ClickDetector), refer to using Players.LocalPlayer
Here’s an example:
local Player = game:GetService'Players'.LocalPlayer
local TextButton = script.Parent
local MarketplaceService = game:GetService'MarketplaceService'
TextButton.MouseButton1Click:Connect(function()
MarketplaceService:PromptGamePassPurchase(Player,idhere)
end)
P.S. I realized how you had ‘player’ as an argument, not ‘Player.’ You can just uncapitalize the letter P if you want to match the new variable ‘Player’.
local Clicker = Instance.new("ClickDetector", script.Parent)
local MarketplaceService = game:GetService'MarketplaceService'
local idhere = 12013123 -- put the gamepass id here
Clicker.MouseClick:Connect(function(Player)
MarketplaceService:PromptGamePassPurchase(Player,idhere)
end)
So when I’m back I’ll test the codes you guys send me but a question, how am I sure it works? What will be on the screen? The general purchase screen or something saying “error you can’t be in studio” or something