Speed gamepass not working

I’m not too sure why its not working… I had it working a week ago and then somehow something somewhere got changed and I no longer have the speed. Any help is welcome!
Here’s the script:

local id - 9559872

game:GetService(“MarketplaceService”).PromptGamePassPurchaseFinished:Connect(function(plr,ido,purchased)
if purchased and ido == id then
plr.Character.Humanoid.WalkSpeed = 100
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
char.Humanoid.WalkSpeed = 100
end
end)
end)

In the future, when posting code to the forums, please put it in a code block. Be sure also to check your console for errors and debug your code if it stops working before posting a thread.

Variables are defined in scripts with an equals, not a subtraction.

local id = 9559872

And from the UserOwnsGamePassAsync function in CharacterAdded, you already have the player object, so why are you redefining the player?

:UserOwnsGamePassAsync(plr.UserId, id) then

In general, your script is somewhat messy. Maintenance and all could be a pain. It’d be best to maintain consistency and avoid redundancy where possible. As well, for PlayerAdded, I normally recommend using a named function instead to ensure it gets called on all players. Some players may join ahead of your function connecting to PlayerAdded.

Here’s a revision idea:

local Players = game:GetService("Players")
local MarketplaceService = game:GetService("MarketplaceService")

local SPEED_PASS_ID = 9559872

local function purchaseFinished(player, gamePassId, isPurchased)
    if isPurchased and gamePassId == SPEED_PASS_ID then
        player.Character.Humanoid.WalkSpeed = 100
    end
end)

local function playerAdded(player)
    -- Reverse function order to reduce UOGPA calls
    if MarketplaceService:UserOwnsGamePassAsync(player.UserId, SPEED_PASS_ID) then
        player.CharacterAdded:Connect(function (character)
            character:WaitForChild("Humanoid").WalkSpeed = 100
        end)
    end
end

MarketplaceService.PromptGamePassPurchaseFinished:Connect(purchaseFinished)
Players.PlayerAdded:Connect(playerAdded)

for _, player in ipairs(Players:GetPlayers()) do
    playerAdded(player)
end
3 Likes

Thank you so much for the help! And sorry about the block, its my first time trying to get help with a script, ill be sure to do that next time :slight_smile: