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

Make the button visible when Player have certain Pass?

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)

5 comments

0

That code seems like it should work, what's the problem?

0

If it's a LocalScript you're running this in then you need to use PlayerOwnsAsset() instead. http://wiki.roblox.com/index.php?title=API:Class/MarketplaceService/PlayerOwnsAsset

0

No I'm running a script. I put that script in the button but when I test it out in the studio the button is just there like the script is not working...

0

Is this a GUI button or a part in the Workspace?

0

a GUI button

1 answer

✓ Accepted answer

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.

1 comment

0

dang dude! thanks!

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