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

Make the button visible when Player have certain Pass?

Asked by
0msh 333 Moderation Voter
6 years ago
Edited 6 years ago

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)
0
That code seems like it should work, what's the problem? User#17862 0 — 6y
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 User#17862 0 — 6y
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... 0msh 333 — 6y
0
Is this a GUI button or a part in the Workspace? User#17862 0 — 6y
0
a GUI button 0msh 333 — 6y

1 answer

Log in to vote
2
Answered by 6 years ago

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.

0
dang dude! thanks! 0msh 333 — 6y
Ad

Answer this question