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

Game Pass GUI Script -- Remove Basic GUI if game pass is owned, and stop basic gui from duplicating?

Two problems:

  1. If they don't have the game pass if gives duplicates of the regular GUI (Every 5 seconds). This is obnoxious because my GUI has moving parts. How do I make it only give one?

  2. How would I remove the regular GUI if they buy the game pass while in game? The script only gives one VIP gui if you join the game with the pass. But I imagine if they buy the pass in game it will have the VIP gui and and regular gui.

Thank you for any help you guys may provide. Here's what I have so far:

Explorer:

Server Script Service

	Script

		RegularGui

		VIPGui

Script:

local mps = game:GetService("MarketplaceService")
local gamepass = #########
script.VIPGui.ResetOnSpawn = false
script.RegularGui.ResetOnSpawn = false
game.Players.PlayerAdded:Connect(function(player)
	while true do
		if mps:UserOwnsGamePassAsync(player.UserId, gamepass) then
			script.VIPGui:Clone().Parent = player.PlayerGui
			--***********LINE TO REMOVE REGULAR GUI********************
		else
			script.RegularGui:Clone().Parent = player.PlayerGui
		end
		wait(5)
	end
end)

1 comment

0

Why are you running a loop at line 6?

1 answer

✓ Accepted answer

Lets stay away from while loops since they are really unnecessary here. Instead we will check whether the player owns the gamepass when they join, and if they purchase one during game we will deal with it then.

For things to be even easier, make sure you create a screengui and set its ResetOnSpawn property to false. This will make it so that once we destroy the gui we won't have to deal with it anymore. **You want to set property through your studio not your script as you have it above. **

SO, How should starterGui look like? Regulargui should already be in there, and visible. VIPGui should should be in there, but not visible. Both with ResetOnSpawn set to false.

Our first script will deal with destroying the gui if you player has the gamepass and making vipgui visible.

local mps = game:GetService("MarketplaceService")
local gamepass = #########

game.Players.PlayerAdded:Connect(function(player)
        if mps:UserOwnsGamePassAsync(player.UserId, gamepass) then
            player.PlayerGui.VIPGui.Visible=true
            player.PlayerGui.RegularGui:Destroy()
        end
end)

simple right?

Now how do we check when the player buys the gamepass? We will use the PromptGamePassPurchaseFinished function of marketplace.

local mps = game:GetService("MarketplaceService")
 
local gamepass = #########

-- Function to handle a completed prompt and purchase
mps.PromptGamePassPurchaseFinished:Connect(function(player, purchasedPassID, purchaseSuccess)
	if purchaseSuccess == true and purchasedPassID == gamepass then
                print("player has bought gamepass")
                player.PlayerGui.VIPGui.Visible=true
                player.PlayerGui.RegularGui:Destroy()
	end
end)

1 comment

0

This worked thank you

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