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

Gamepass button giving function Not Working?

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

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.

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