[Solved] - updating enabled gui value

Hello! I’m experiencing a synchronization issue and I’d like to share it.

The situation is as follows: when enabling the GUI from my proximity prompt, everything works perfectly. However, when pressing the “exitGuiButton” button in the local script, the GUI hides as expected. The issue arises when I attempt to show the GUI again using the proximity prompt; at this point, the enablement state does not update correctly.

Any suggestions or does anyone know how to resolve this problem? I would appreciate any help, as the GUI does not reappear when using the proximity prompt.

script:

local proxPrompt = script.Parent.ProximityPrompt

proxPrompt.Triggered:Connect(function(player)
	print("ProximityPrompt triggered!")

	local playerGui = player:FindFirstChild("PlayerGui")
	if playerGui then
		local rbGui = playerGui:FindFirstChild("Rebirth_UI")
		if rbGui then
			rbGui.Enabled = true
		else
			warn("Rebirth_UI not found in PlayerGui for player " .. player.Name)
		end
	else
		warn("PlayerGui not found for player " .. player.Name)
	end	
end)

localscript:

local exitGuiButton = script.Parent

exitGuiButton.MouseButton1Click:Connect(function()
	local player = game.Players.LocalPlayer

	local playerGui = player:WaitForChild("PlayerGui")

	local guiToHide = playerGui:WaitForChild("Rebirth_UI")

	guiToHide.Enabled = false

	print("Rebirth_UI has been hidden.")
end)

I’m guessing the problem arises because of a replication issue. You originally enable the gui on the server however when you press the button and the local scripts disables the gui on the client but doesn’t replicate to the server, so when you re-enable via the proximity prompt the server remains enabled anyway and doesn’t detect a change and doesn’t replicate to the client.

server: disabled → enabled → enabled → enabled → enabled → etc…
client: disabled → enabled → disabled → disabled → disabled → etc…

I’m guessing you understand the client/server relationship within roblox. Local scripts affect the client whilst scripts effect the server.

1 Like

Thank you very much, I was able to solve it by updating the information to the server.

localscript:

local exitGuiButton = script.Parent
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local toggleRebirthUI = ReplicatedStorage:WaitForChild("ToggleRebirthUI")

exitGuiButton.MouseButton1Click:Connect(function()
	local player = game.Players.LocalPlayer

	local playerGui = player:WaitForChild("PlayerGui")

	local guiToHide = playerGui:WaitForChild("Rebirth_UI")

	guiToHide.Enabled = false

	print("Rebirth_UI has been hidden.") 

	toggleRebirthUI:FireServer(false)
end)

server-side

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local toggleRebirthUI = ReplicatedStorage:WaitForChild("ToggleRebirthUI")

toggleRebirthUI.OnServerEvent:Connect(function(player, enabled)
	local playerGui = player:FindFirstChild("PlayerGui")
	if playerGui then
		local rbGui = playerGui:FindFirstChild("Rebirth_UI")
		if rbGui then
			-- Update the GUI's enabled state
			rbGui.Enabled = enabled
		else
			warn("Rebirth_UI not found in PlayerGui for player " .. player.Name)
		end
	else
		warn("PlayerGui not found for player " .. player.Name)
	end
end)
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.