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 6 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

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

Please help

2 answers

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

basically that.

Ad
Log in to vote
0
Answered by
popeeyy 493 Moderation Voter
6 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:

1local player = game.Players.LocalPlayer
2local GamepassID = 4636698
3local marketplaceService = game:GetService('MarketplaceService')
4 
5if marketplaceService:UserOwnsGamePassAsync(player.UserId, GamepassID) then
6    script.Parent.Visible = true
7else
8    script.Parent.Visible = false
9end

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 — 6y

Answer this question