GUI not becoming visible again after changing it with a script

Hello

So I have a script that handles receipts for a game I’m working on and basically when a player buys a donation developer product it will make a thank you GUI visible. Now it works the first time but after the second time the frame doesn’t become visible. I have verified that the function that changes the state of the frame is being called. I also have another script inside the a button in the frame that changes it’s visibility when the user clicks on the button. I am not sure what is wrong and theoretically it should work. Also there are not any errors in output

Here is my script:

local MarketplaceService = game:GetService("MarketplaceService")
local DataStoreService = game:GetService("DataStoreService")
local Players = game:GetService("Players")

-- Data store for tracking purchases that were successfully processed
local purchaseHistoryStore = DataStoreService:GetDataStore("PurchaseHistory")

-- Table setup containing product IDs and functions for handling purchases
local productFunctions = {}
productFunctions[000000000] = function(receipt, player)
	print("Donation Recieved")
	player.PlayerGui.DonateGUI:WaitForChild("Purchased").Visible = true
	return true
end

-- The core 'ProcessReceipt' callback function
local function processReceipt(receiptInfo)

	-- Determine if the product was already granted by checking the data store  
	local playerProductKey = receiptInfo.PlayerId .. "_" .. receiptInfo.PurchaseId
	local purchased = false
	local success, errorMessage = pcall(function()
		purchased = purchaseHistoryStore:GetAsync(playerProductKey)
	end)
	-- If purchase was recorded, the product was already granted
	if success and purchased then
		return Enum.ProductPurchaseDecision.PurchaseGranted
	elseif not success then
		error("Data store error:" .. errorMessage)
	end

	-- Find the player who made the purchase in the server
	local player = Players:GetPlayerByUserId(receiptInfo.PlayerId)
	if not player then
		-- The player probably left the game
		-- If they come back, the callback will be called again
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end

	-- Look up handler function from 'productFunctions' table above
	local handler = productFunctions[receiptInfo.ProductId]

	-- Call the handler function and catch any errors
	local success, result = pcall(handler, receiptInfo, player)
	if not success or not result then
		warn("Error occurred while processing a product purchase")
		print("ProductId:", receiptInfo.ProductId)
		print("Player:", player)
		print(success, result)
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end

	-- Record transaction in data store so it isn't granted again
	local success, errorMessage = pcall(function()
		purchaseHistoryStore:SetAsync(playerProductKey, true)
	end)
	if not success then
		error("Cannot save purchase data: " .. errorMessage)
	end

	-- IMPORTANT: Tell Roblox that the game successfully handled the purchase
	return Enum.ProductPurchaseDecision.PurchaseGranted
	
end

-- Set the callback; this can only be done once by one script on the server! 
MarketplaceService.ProcessReceipt = processReceipt

Nevermind figured it out it’s because I was opening the GUI on a server script and closing it on a local script.
Because of this the server thinks the UI is already open (because it cant see changes made on the client) and as a result it doesn’t change the visibility of the UI

3 Likes