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

Gamepass ownership update without rejoin game?

Asked by
Aozwel 71
3 years ago

Hey there,

I've got this script that checks if a player owns the gamepass then would pass the code, But if you buy the gamepass while in-game it would not give the correct coins until they rejoin?

Is there a simple way to check if they bought it?

Script:
local MarketplaceService = game:GetService("MarketplaceService")
game.Players.PlayerAdded:Connect(function(player)
local amount = 2
local timedelay = 5
local currencyname = "Coins"
local gamepassId = 14144444

    if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId,gamepassId) then
    while true do
    wait(timedelay)
            player.leaderstats[currencyname].Value = player.leaderstats[currencyname].Value + amount*2 
            end
    else
        while true do
        wait(timedelay)
        player.leaderstats[currencyname].Value = player.leaderstats[currencyname].Value + amount
        end
    end
end)

Thank you,

1 answer

Log in to vote
1
Answered by 3 years ago
Edited 3 years ago

Here is a fix, simply add the gamepass check inside the while loop. Fixed Script:

local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local amount = 2
local timedelay = 5
local currencyname = "Coins"
local gamepassId = 14144444

Players.PlayerAdded:Connect(function(Player)
    while wait(timedelay) do
        if Player and Player.Parent then
            local leaderstats = Player:FindFirstChild("leaderstats")
            if leaderstats then
                local Currency = leaderstats:FindFirstChild(Currency)
                if Currency then
                    if MarketplaceService:UserOwnsGamePassAsync(Player.UserId,gamepassId) then
                        Currency.Value += amount*2
                    else
                        Currency.Value += amount
                    end
                end
            end
        else
            break
        end
    end
end)

Reasons for Changes I made: You assigned a variable to MarketplaceService but didnt seem to use it, i use it here Players is also a service, assigned a variable to it too removed second while loop as

0
Worked, Thanks alot! Aozwel 71 — 3y
0
happy to help Lord_WitherAlt 206 — 3y
Ad

Answer this question