Need help with disabling GUI

Im trying to make a system where when the player dies, if they have no more lives left, A developer product appears so they can respawn, it works fine, but the GUI wont go away, Ive tried a Local Script and a Server Script, Neither one works, Here is the Local Script:

local plr = game.Players.LocalPlayer
local hum = plr.Character:WaitForChild("Humanoid")
local LL = plr.ItemsFolder.LivesLeft
local MarketplaceService = game:GetService('MarketplaceService')
local RespawnButton = plr.PlayerGui.DiedScreen1.MainFrame.ReviveButton
local id = 1884043455

RespawnButton.MouseButton1Click:Connect(function()
if LL.Value == 0 then
MarketplaceService:PromptProductPurchase(plr, id)


local success, errormessage = pcall(function()
	MarketplaceService.PromptProductPurchaseFinished:Connect(function(PlayerId, GamepassId, IsPurchased)
		if IsPurchased == Enum.ProductPurchaseDecision.PurchaseGranted then
			plr.PlayerGui.DiedScreen1.Enabled = false
		
		end
		end)
end)
end
end)

And here is the Server Script:

local char = script.Parent
local plr = game.Players:GetPlayerFromCharacter(char)
local hum = char:WaitForChild("Humanoid")
local LL = plr.ItemsFolder.LivesLeft
local Bought = plr.ItemsFolder.Bought
local MarketplaceService = game:GetService('MarketplaceService')
local RS = game:GetService("ReplicatedStorage")
local PU = RS.PopUp
local id = 1884043455

	PU.OnServerEvent:Connect(function()
		MarketplaceService:PromptProductPurchase(plr, id)

	local success, errormessage = pcall(function()
		MarketplaceService.PromptProductPurchaseFinished:Connect(function(PlayerId, GamepassId, IsPurchased)
			if IsPurchased == Enum.ProductPurchaseDecision.PurchaseGranted then
				plr.PlayerGui.DiedScreen1.Enabled = false
				Bought.Value = true
				wait(1)
				Bought.Value = false
			end
		end)
	end)

	if not success then
		print("uh oh it failed...error:", errormessage)
	end
	end)

there is also a Local Script that is supposed to Disable the GUI when the “Bought” Value is set to true.

2 Likes

Not sure if this is why the UI wont go away, but you currently do not have any process receipt function:
MarketplaceService | Documentation - Roblox Creator Hub

Also, you’re connecting PromptProductFinished on the server after every time PU is fired. Just connect it once, or you’ll have multiple instances of that code running after a purchase happens.

2 Likes