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

I am so confused with this MarketplaceService Help?

Asked by 5 years ago

I am making a speed gamepass script and found the gamepass script form roblox Developer Hub https://developer.roblox.com/en-us/articles/Game-Passes-One-Time-Purchases so i edited it for my needs to make the speed go faster but for some reason it never notices when the players character is added.

I'll show you what I did.

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

local SpeedPassID = 6810819  -- Change this to your game pass ID

Players.PlayerAdded:Connect(function(plr)

    local hasSpeedPass = false

    -- Check if the player already owns the game pass
    local success, message = pcall(function()
        hasSpeedPass = MarketplaceService:UserOwnsGamePassAsync(plr.UserId, SpeedPassID)
    end)

    -- If there's an error, issue a warning and exit the function
    if not success then
        warn("Error while checking if player has pass: " .. tostring(message))--this never prints 
        return
    end

    if hasSpeedPass == true then
        print(plr.Name .. " owns the game pass with ID " .. SpeedPassID)--this always prints

        plr.CharacterAdded:Connect(function(char)--broken?
            print("Test")-- this never prints
        end)

    end
end)

why is this not working and how can i fix?

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

I fixed it myself: like this instead

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

local SpeedPassID = 6810819  -- Change this to your game pass ID

Players.PlayerAdded:Connect(function(plr)

    plr.CharacterAdded:Connect(function(char)--broken?


        local hasSpeedPass = false

        -- Check if the player already owns the game pass
        local success, message = pcall(function()
            hasSpeedPass = MarketplaceService:UserOwnsGamePassAsync(plr.UserId, SpeedPassID)
        end)

        -- If there's an error, issue a warning and exit the function
        if not success then
            warn("Error while checking if player has pass: " .. tostring(message))--this never prints 
            return
        end

        if hasSpeedPass == true then
            print(plr.Name .. " owns the game pass with ID " .. SpeedPassID)--this always prints
            local hum = char:FindFirstChildOfClass("Humanoid")
            if hum then
                hum.WalkSpeed = 32
            end

        end
    end)
end)
Ad

Answer this question