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

why is the gamepass not coming after you rejoin after buying?

Asked by 2 years ago
Edited 2 years ago

THIS SCRIPT IN STARTER PLAYER SCRIPTS local script

local MarketPlaceService = game:GetService("MarketplaceService")

local gamePassID = 18759963

local function promptPurchase()

    local player = game.Players.LocalPlayer
    local haspass = false

    local success, message = pcall(function()
        haspass = MarketPlaceService:UserOwnsGamePassAsync(player.UserID, gamePassID)
    end)

    if haspass == true then
        print("Player Aldready has the gamepass")
    else
        MarketPlaceService:PromptGamePassPurchase(player, gamePassID)
    end
end

wait(5)
promptPurchase()

this in serverscriptservice

local MarketPlaceService = game:GetService("MarketplaceService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local sword = ReplicatedStorage:WaitForChild("ClassicSword")

local gamePassID = 18759963

MarketPlaceService.PromptGamePassPurchaseFinished:Connect(function(player, purchasePassID, purchaseSuccess)

    if purchaseSuccess == true and purchasePassID == gamePassID then
        print(player.Name.. " purchased the sword gamepass")
        sword.Parent = player.Character
    end

end)

this also in server script service but in another script

local MarketPlaceService = game:GetService("MarketplaceService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local sword = ReplicatedStorage:WaitForChild("ClassicSword")

local gamePassID = 18759963


game.Players.PlayerAdded:Connect(function(player)
    wait(5)
    local char = game.Workspace:FindFirstChild(player.Name)
    local haspass = false

    local success, message = pcall(function()
        haspass = MarketPlaceService:UserOwnsGamePassAsync(player.UserID, gamePassID)
    end)

    if haspass == true then
        print("Player has sword gamepass")
        sword.Parent = char
    end
end)

0
did it work? Xyternal 247 — 2y
0
btw, get rid of that script in start player scripts. Its useless Xyternal 247 — 2y

1 answer

Log in to vote
0
Answered by
Xyternal 247 Moderation Voter
2 years ago

So you want to check if a player has a gamepass right? Well use this script. Everytime a player joins, it checks if the player has a gamepass.

local id = YOUR_ID_HERE

game:GetService("MarketplaceService").PromptGamePassPurchaseFinished:Connect(function(plr,ido,purchased)
    if purchased and ido == id then
    -- your code when they have gamepass
    end
end)

game.Players.PlayerAdded:Connect(function(plr)
    plr.CharacterAdded:connect(function(char)
        if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(game.Players[char.Name].UserId, id) then
            --copypaste the script you wrote earlier
        end
    end)
end)

if it worked don't forget to accept it :P

Ad

Answer this question