Shop GUI not opening after being closed

Hey guys, I have made a GUI shop for my game.
image
When I test my game, the shop GUI will pop up when I touch the shop part at the first time but after closing the shop with the close button and touch the shop part again, the shop won’t pop up. The followings are the codes and screenshot of the explorer tab of the game:

Organisation of the game

Shop GUI
Picture1
Shop part
shop

Shop part script
	script.Parent.Touched:Connect(function(hit)
		if hit.Parent:FindFirstChild("Humanoid") then
			game:GetService("Players"):FindFirstChild(hit.Parent.Name).PlayerGui.GUIS.Shop.Visible = true
		end
	end)
	wait(0.1)
end````
Close GUI script
local shop = script.Parent.Parent

local function close()
	shop.Visible = false
end

button.MouseButton1Down:Connect(close)````
HideOnGameStart script

script.Parent.Visible = false

Sorry if it is a simple mistake as I am a beginner in scripting

2 Likes

It is because you are performing the change on server so Client thinks it is still opened.

1 Like

Hmmm…then what should I do to avoid this?

Going off of @caviarbro’s point - you should remedy this by using a RemoteEvent.

You would use the RemoteEvent to open the UI on the client instead of on the server. That way when you close it, the client knows that the UI element is indeed visible (and vice versa).

1 Like

RemoteEvents/RemoteFunction to sent information to client to close it or just simply use magnitude opening/closing.

1 Like

You can try to use this ^^^.

1 Like

Thanks all. But can you please give me an example of how to use the RemoteEvents?

Just noticed the page I linked in my reply might not’ve worked at first - it has examples:

The general philosophy is that you fire a RemoteEvent on the server to the player who touched the shop area. On the client, you check for the event of that RemoteEvent firing and trigger a function to open the shop UI.

1 Like

An alternative to using touch events is the Zone module created by ForeverHD:

Can be ran on client or server.

3 Likes

This is really nice, it helps me a lot in my game! Thanks for sharing! :+1: :+1: :+1: