I've been trying to make a button that only available when the player that have a certain gamepass. I am new to scripting so don't laugh D: . Here's what I have:
local id = 889632521 game.Players.PlayerAdded:connect(function(player) if game:GetService("GamePassService"):PlayerHasPass(player, id) then script.Parent.Visible = true else script.Parent.Visible = false end end)
If your game is FilteringEnabled
, you should use a local script to toggle the buttons. Also, you can use LocalPlayer
(in the Players
service) if you use local scripts as well. This is a good way to create a reference to the player. Here is how it's done:
local id = 889632521 local player = game.Players.LocalPlayer if game:GetService("MarketplaceService"):PlayerOwnsAsset(player, id) then -- PlayerOwnsAsset can search for any asset a player owns, including gamepasses. script.Parent.Visible = true else script.Parent.Visible = false end
Any questions? Please leave them in the comments below. Thanks.