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

(UNSOLVED) Help With GamePass Only Gui showing when clicking a button?

I have a script for a text button that I want to prompt a purchase for the gamepass and if the player owns the gamepass I want to open a frame here is my code:

local players = game:GetService("Players")
local MPS = game:GetService("MarketplaceService")
local passId = 39692796 

game.StarterGui.VipScreen.VipOpener.MouseButton1Click:Connect(function()
game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
			if MPS:UserOwnsGamePassAsync(player.UserId,39692796) then
			local UI = script.VIP:clone()
			UI.Parent = game.PlayerGui
		end
	end)
end)
end)

The script is in ServerScriptService, Thanks.

1 answer

✓ Accepted answer

i see 3 problems

problem 1 is that you don't check each player individually, if one has the pass then every player can access the UI.

problem 2 is that you wait for a player to get added after you click the button.

problem 3 is that you clone the ui to the playergui, not the players individual screengui.

You could restructure the code as so:

local players = game:GetService("Players")
local MPS = game:GetService("MarketplaceService")
local passId = 39692796 
game.Players.PlayerAdded:Connect(function(player) -- player joins
	player.CharacterAdded:Connect(function() -- avatar loads
		if MPS:UserOwnsGamePassAsync(player.UserId,39692796) then -- check for pass
			local fun, fun2 = nil, nil -- set some variables for functions
			fun = game.StarterGui.VipScreen.VipOpener.MouseButton1Click:Connect(function() -- button clicked
				local UI = script.VIP:clone()
				UI.Parent = player.PlayerGui -- add a screenui object, and then put the ui into there
			end)
			fun2 = game.Players.PlayerRemoving:Connect(function() -- player is leaving
				fun:Disconnet() -- cancel
				fun2:Disconnect() -- cancel
			end)
		end
	end)
end)

there may be some errors in the code i edited but it should work

i hope this works

4 comments

0

Hm Wierd it's not adding to the players Gui and how would I make it so a purchase prompt pops up if you don't own the pass thanks.

0

replace line 10 to add it in to the player ui, as for the purchase prompt do it yourself watch a tutorial

0

Ok Thanks

0

Yw

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