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

Game pass script not functioning?

Hi there, back with another question! I can't see the error in this script I wrote, which allows for a player with a game pass to be assigned a GUI.

function assign(property, player)
	local GUI = game.ReplicatedStorage:FindFirstChild("Gamepass"..property):GetChildren()
	for i = 1,#GUI do
		GUI[i]:Clone().Parent = player.PlayerGui.ScreenGui.Avatar:FindFirstChild(property)
	end
end

	
game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		wait(0.1)
		if game:GetService("GamePassService"):PlayerHasPass(player, 4950898) then 
       		assign("Colors",player)
			assign("Faces",player)
    	end
	end)
end)


Any help is appreciated, thanks scripters!

1 answer

✓ Accepted answer

I'm assuming the error is on line 12. The PlayerHasPass method has been deprecated not too long ago, so you'll need to update it using MarketplaceService's UserOwnsGamePassAsync.

function assign(property, player)
    local GUI = game.ReplicatedStorage:FindFirstChild("Gamepass"..property):GetChildren()
    for i = 1,#GUI do
        GUI[i]:Clone().Parent = player.PlayerGui.ScreenGui.Avatar:FindFirstChild(property)
    end
end


game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
        wait(0.1)
        if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, 4950898) then -- Instead of giving the player's instance in the first argument, we pass the player's user id.
            assign("Colors",player)
            assign("Faces",player)
        end
    end)
end)

Sources: https://wiki.roblox.com/index.php?title=API:Class/MarketplaceService/UserOwnsGamePassAsync

If you have any problems with this script, let me know in the comments. If it works and you're satisfied, be sure to accept the answer!

1 comment

0

It works! Thanks a lot!

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