Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why isn't my game pass purchase working?

Asked by 4 years ago
Edited 4 years ago

I'm trying to make a GUI where you can press certain buttons to purchase a game pass. When I do this, the purchase option appears, and when I purchase it, the game pass script isn't working. When I click the button again, it asks me if I want to purchase it again, as if I never purchased it.

Here is my button script for the purchase prompt:

local player = game.Players.LocalPlayer
local id = 123 -- Using a random number for the game pass id as the example

local market = game:GetService("MarketplaceService")

function proceedPurchase()
    if not market:UserOwnsGamePassAsync(player.UserId, id) then
        market:PromptGamePassPurchase(player, id)
    end
end

script.Parent.MouseButton1Click:Connect(proceedPurchase)

I also have the other script that will perform the action with the game pass.

local p = game.Players.LocalPlayer
local f = p.leaderstats:WaitForChild("Fizz")
wait()
local h = p.Character:WaitForChild("Humanoid")
local m = game:GetService("MarketplaceService")

local function changeSpeed()
    if  m:UserOwnsGamePassAsync(p.UserId, 123) then
        h.WalkSpeed = (((f.Value)/(5))+1)*2
        print("Walkspeed updated. Player owns 2x Speed!")
    else
        h.WalkSpeed = ((f.Value)/(5))+1
        print("Walkspeed updated. Can not find 2x Speed.")
    end

end

changeSpeed() -- this is to update the speed when they join

f.Changed:Connect(changeSpeed)

Answer this question