Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why does my gamepass ID not work?

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

✓ Accepted answer

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.