Why Is This Gui Only Opening Once?

I have a part that opens a gui, then a button inside that gui which closes it. It opens the first time, then doesn’t open the second time after I close.

Script inside part:

local part = script.Parent
local players = game:GetService("Players")

local function opengui(player)
	player.PlayerGui.RebirthGUI.MainFrame.Visible = true
end

part.Touched:Connect(function(hit)
	local char = hit.Parent
	local player = players:GetPlayerFromCharacter(char)
	local hum = char:WaitForChild("Humanoid")
	print(player)
	opengui(player)
	hum.WalkSpeed = 0
end)

Script inside Button:

local btn = script.Parent
local gui = script.Parent.Parent
local player = game.Players.LocalPlayer
local char = player.Character
local hum = char:WaitForChild("Humanoid")

btn.MouseButton1Click:Connect(function()
	gui.Visible = false
	hum.WalkSpeed = 16
end)

This is what I usually do and it works, is there any reason it isn’t now?

Any errors in the output window?

Is it printing the player when you hit it a second time?

Wait… Not sure if this helps, but Touched events will fire multiple times when a player touches them.
Check to see if you have multiple hits causing multiple GUIs to open.
If so you may need a debounce to keep the function from being spammed.

The script in which the UI is opens runs on the server, while the one that closes it is ran on the client. The server still thinks that the UI is opened because the changes on the client don’t replicate to the server, which is why it doesn’t open it more than once.

You can fix this by using a RemoteEvent’s :FireClient() method to open the UI on the client.

1 Like

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