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

Gamepass button giving function Not Working?

Asked by 4 years ago
local G = 7542570 --< Gamepass id
game.Players.PlayerAdded:Connect(function(player)
    game.Players.ChildAdded:Connect(function()
        local Gam = game:GetService("MarketplaceService")
        if Gam:UserOwnsGamePassAsync(player.userId , G) then
            local NewButton = script.ChaosInsurgency:Clone()
            NewButton.Parent = player.PlayerGui.MainMenu.TeamSelect.Teams
        end 
    end)
end)

I run the game and the Chaos Insurgency Button does not end up where its meant to be when the player joins.

1 answer

Log in to vote
0
Answered by
Robowon1 323 Moderation Voter
4 years ago
local G = 7542570 
local Gam = game:GetService("MarketplaceService")
game.Players.PlayerAdded:Connect(function(player)

        if Gam:UserOwnsGamePassAsync(player.userId , G) then
            local NewButton = script.ChaosInsurgency:Clone()
            NewButton.Parent = player.PlayerGui.MainMenu.TeamSelect.Teams
        end 
    end)

You wrote game.Players.ChildAdded within the game.Players.PlayerAdded, meaning that the player has already been added when the script waits for a child to be added.

And also make sure in future scripts you define "MarketPlaceService" earlier rather than defining it every time.

Ad

Answer this question