GUI only shows once

Hi! So I made a part where you can touch it with your character and the gui will pop up. To get out of it, you press the x button on the gui and it will disappear. The problem is, the second time you touch the part, the gui will not show up again. Here is my script:

local part = script.Parent

part.Touched:Connect(function(hit)
	print("started")
	if hit.Parent:FindFirstChild("Humanoid") then
		print("started")
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		
			player.PlayerGui.Shop.ShopGUI.Visible = true
			player.PlayerGui.Shop.Background.Visible = true
			
			
			end
		
	
end)

Thanks!

It may be because when you’re making it dissappear you might be disabling it instead of setting the value of visible to false.

Does the ‘X’ just make those gui in that script visible = false, or?

the X button might be disabling the whole gui can you show us the button code?

X button script:

local gui = script.Parent.Parent

script.Parent.MouseButton1Click:Connect(function()
	print("started")
	gui.Visible = false
	gui.Parent.Background.Visible = false

end)

Here is the X button script:

local gui = script.Parent.Parent

script.Parent.MouseButton1Click:Connect(function()
	print("started")
	gui.Visible = false
	gui.Parent.Background.Visible = false

end)
local gui = script.Parent.Parent

script.Parent.MouseButton1Click:Connect(function()
	print("started")
	gui.Visible = false
	gui.Parent.Background.Visible = false

end)

is “gui” the ShopGUI? char limit

apparently, your issue here is that you’re setting the gui visibility in the “server” to true but you’re changing it to false in the client.

So should I change the X buttons script to regular?

wait isn’t the x button local? it should be a localscript.

It is a localscript. I misspoke

you can fix that by two ways,

  1. changing the TouchedPart script to a localscript and placing it in StarterCharacterScripts.
    which would look like this
local player = game.Players.LocalPlayer
local part = game.Workspace.Part -- Your Part's Path

part.Touched:Connect(function(hit)
	print("started")
	if hit.Parent:FindFirstChild("Humanoid") then
			player.PlayerGui.Shop.ShopGUI.Visible = true
			player.PlayerGui.Shop.Background.Visible = true
			
			
			end
		
	
end)
  1. keeping the TouchedPart script as a script but firing a remote to the client to make the GUI Invisible
local part = script.Parent

part.Touched:Connect(function(hit)
	print("started")
	if hit.Parent:FindFirstChild("Humanoid") then
		print("started")
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		        game.ReplicatedStorage.RemoteEvent:FireClient(player)
	end
end)
-- LocalScript
local player = game.Players.LocalPlayer
game.ReplicatedStorage.Remote.OnClientEvent:Connect(function()
	player.PlayerGui.Shop.ShopGUI.Visible = true
    player.PlayerGui.Shop.Background.Visible = true
end)
1 Like

Could you show the hierarchy for all the GUIs?

The first way worked perfectly, thanks!

1 Like

Just a bit of context as to why it didn’t work in the first place.