Opening GUI by clicking a block

So I wanted to make a code that opens GUI with a block for an ice cream shop but I can’t get it to work.

I know you guys may have answered this question in the past but I’m almost a complete beginner in scripting. I’ve tried looking for a code to open the GUI and 1 of them kind of worked. The problem is that this code only works when you first click the block when you first start the game ( I tried multiple times). Like I said Before I’m not good at scripting but I think the clickdetector waits for the mouseclick and then it opens the frame inside the GUI but it only reads the code once.

script.Parent.ClickDetector.MouseClick:Connect(function(player)
	player:WaitForChild("PlayerGui").IcecreamShop.mgs.Visible = true
	end) --this is someone else's code but edited (im not good at scripting)--

I tried using the “while true do” code to try to solve this problem because I thought if it only happened once then it was probably because the script ended after it opens the GUI. but the same thing happens

while true do
script.Parent.ClickDetector.MouseClick:Connect(function(player)
	player:WaitForChild("PlayerGui").IcecreamShop.mgs.Visible = true
	end)
	wait(1)
end

any help will be greatly appreciated, thanks.

1 Like

I would use a remote event:

script.Parent.ClickDetector.MouseClick:Connect(function(player)
	game.ReplicatedStorage.RemoteEvent:FireClient(player)
	end)

And use this as a local script inside of the GUI thing:

game.ReplicatedStorage.RemoteEvent.OnClientEvent:Connect(function()
script.Parent.Visible = true
end)
4 Likes