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

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

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

✓ Accepted answer
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.

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.

1 comment

0

There's also an Enabled property on the ScreenGUI itself :D

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