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

How to make a GUI that can be accessed by a player who owns a asset?

Asked by 5 years ago

How to make a GUI that can be accessed by a player who owns a asset, shirt, game pass etc., this is the script i used on the gamepass

GamepassID = 4636698
game.Players.PlayerAdded:connect(function(plr)
    if game:GetService("GamePassService"):PlayerHasPass(plr,GamepassID) then
        game.StarterGui.Shop.Frame.Visible = true
    end
end)

Please help

2 answers

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago
game.Players.PlayerAdded:Connect(function(plr)
    if game:GetService("MarketplaceService"):PlayerOwnsAsset(plr.userId,<asset id>) then
        plr.PlayerGui.ScreenGui.Enabled = true
    else
        plr.PlayerGui.ScreenGui.Enabled = false
    end
end)

basically that.

Ad
Log in to vote
0
Answered by
popeeyy 493 Moderation Voter
5 years ago

First, you should put this inside the gui. Make a LocalScript right inside it so script.Parent is the Frame, like this https://gyazo.com/4792fdcbc016f043c87cb607cc02a56a.

Here's the code you should insert:

local player = game.Players.LocalPlayer
local GamepassID = 4636698
local marketplaceService = game:GetService('MarketplaceService')

if marketplaceService:UserOwnsGamePassAsync(player.UserId, GamepassID) then
    script.Parent.Visible = true
else
    script.Parent.Visible = false
end

This checks if the player has the gamepass using MarketplaceService, then sets it visible or invisible. The players gui is also in PlayerGui, but it's better to use a LocalScript inside the GUI.

0
There's also an Enabled property on the ScreenGUI itself :D developer180 15 — 5y

Answer this question