Hello there! I have been looking at youtube tutorials and just cant find out what the error is with my script. Its supposed to when you click show you that you can buy a gamepass but i tried using some prints. Everything printed exept for print 5 here is the script:
local plr = game.Players.LocalPlayer
print(“print1”)
local button = script.Parent
print(“print2”)
local MarketplaceService = game:GetService(“MarketplaceService”)
print(“print3”)
script.Parent.MouseButton1Click:Connect(function()
print(“print4”)
MarketplaceService:PromptGamePassPurchase(plr, 0000000) --id instead of 0000000
print(“print5”)
end)
AFAIK you can’t prompt gamepass purchases on the client (LocalScript). You have to call a RemoteEvent to tell the server that the client calling it wants to buy an item.
Instead of just providing where the script failed could you give any errors that were logged in the Output. 95% of the time these clarify the issue rather quickly.
When testing in studio and i already own the gamepass and its in team create is it supposed to say “You already own this item. Your account has not been charged.”?
Create a RemoteEvent inside of ReplicatedStorage called “PromptPurchase”. Then, create a ServerScript inside of ServerScriptService with the following code:
local MarketplaceService = game:GetService("MarketplaceService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local promt = ReplicatedStorage:WaitForChild("PromtPurchase")
local passId = -- your GamePassId
promt.OnServerEvent:Connect(function(player)
MarketplaceService:PromptGamePassPurchase(player, passId)
end)
Then, in a LocalScript inside of your button, write the following code:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local prompt = ReplicatedStorage:WaitForChild("PromptPurchase")
script.Parent.MouseButton1Click:Connect(function()
prompt:FireServer()
end)
I scripted this quickly without any testing, so please let me know if you run into any errors.