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

Why does my gamepass ID not work?

Asked by 9 years ago

Anyways, what I am trying to make is a script that if they have the specific game pass, they can have infinite stamina, but the stamina value is located in the backpack, under a local script named globalfunctions. The problem is that for some reason it cant seem to find "Backpack".

local passId = 318909278

function isAuthenticated(player)
    return game:GetService("GamePassService"):PlayerHasPass(player, passId)
end

game.Players.PlayerAdded:connect(function(plr)
    if isAuthenticated(plr) then
        repeat wait() until plr.Backpack.GlobalFunctions.Stamina
        spawn(function()
            while wait() do 
                plr.Backpack.GlobalFunctions.Stamina.Value = 100
            end
        end)
    end
end)

Anyways, output says this: http://prntscr.com/91oxpt

1 answer

Log in to vote
0
Answered by
Im_Kritz 334 Moderation Voter
9 years ago

Well yeah, the code can't find the backpack. If I had to guess, I think the code checks for the backpack way too early, that the backpack wasn't loaded yet.

All I did was added a wait on finding the backpack:

local passId = 318909278

function isAuthenticated(player)
    return game:GetService("GamePassService"):PlayerHasPass(player, passId)
end

game.Players.PlayerAdded:connect(function(plr)
    if isAuthenticated(plr) then
        repeat wait() until plr:WaitForChild('Backpack').GlobalFunctions.Stamina
        spawn(function()
            while wait() do 
                plr.Backpack.GlobalFunctions.Stamina.Value = 100
            end
        end)
    end
end)
Ad

Answer this question