Function only happens once and then never again

Hello! as my profile says I’m more of an artist than anything. I’m trying to teach myself Lua but it’s not going too well, most of my code has been from here or frankensteined together shoddily, but luckily I can finally post here which means I can finally ask for help! I’m developing hangout space-type games, like those weirdcore ones you see, I’m trying to make a ui for a note appear on a Proximity Prompt and a Remote event which I got from a different tutorial, and then disappear when you hit the closing button (which I got from a tutorial and then modified). The code I pasted and re-worked is working fine- until I try to do it more than once, code is below, and a video of my problem will be attached as well.

Code on the part itself (normal Script):
> local RemoteEvent = game.ReplicatedStorage:WaitForChild(“open note1”) --Variable for Remote Event

local prox = script.Parent.ProximityPrompt --Variable for Proximity Prompt

prox.Triggered:Connect(function(player) --Code runs when the Player triggers the Proximity Prompt
RemoteEvent:FireClient(player) --Fires the Remote Event
end)

Code on the text gui (Local Script):

local RemoteEvent = game.ReplicatedStorage:WaitForChild(“open note1”) --Variable for the Remote Event in Replicated Storage

RemoteEvent.OnClientEvent:Connect(function() --Code runs when the Remote Event is fired

script.Parent.Frame.Visible = true --Makes the frame visible

end)

Code on the image button (Local Script):

local Button = script.Parent
local GUI = Button.Parent

Button.MouseButton1Down:Connect(function()
if GUI.Visible == true then
GUI.Visible = false

end
end)

Video:
robloxapp-20240514-1523164.wmv (1.7 MB)

Apologies if I take a while, I am a total newbie at coding, and still don’t understand most of this, Playing on a test map available from my profile, I generally test everything I make there even if the games I’m making don’t add up. I’ve tried searching other threads to find what I’m looking for but none has helped so far, if you need any screenshots or anything let me know! thank you for potential help.

I don’t know the answer to your problem, but you should be using .Activated for buttons, it’s compatible for every device (mobile included)

Where would I put that in the script?

Use .Activated instead of .MouseButton1Down

I had similar problems before. It doesn’t work because of the client versus server problem.
When you click closing button in your Gui it sets the Gui invisible. BUT because you’re making it in local script it’s still visible on the server. The server thinks it’s visible, because you changed it on the client side. So the solution is to make all the interaction with the Gui either on server(only normal scripts) or on client.(only local scripts)

I tried changing the local scripts to normal scripts and it didn’t work. any other advice?

EDIT: should’ve added that it also just made it stop working entirely.

Maybe it just didn’t work because of some errors?
I’ve just noticed that the code which you sent as the code in the part is same as code in image button.
Could you provide the code inside the part?

ah, that was probably an accident, didn’t notice that! here it is! I’ll edit that mistake real quick.

local RemoteEvent = game.ReplicatedStorage:WaitForChild(“open note1”) --Variable for Remote Event
local prox = script.Parent.ProximityPrompt --Variable for Proximity Prompt

prox.Triggered:Connect(function(player) --Code runs when the Player triggers the Proximity Prompt
RemoteEvent:FireClient(player) --Fires the Remote Event
end)

Are you making invisible the same frame in your textGui and image button code?
If that doesn’t work could you take a screenshot of explorer with the Gui and image button and text gui scripts?

Hello! looked over my code again, should’ve done everything right. heres the explorer.
(apologies for a late response, had finals week, a new kitten in the house, and I just now caught a cold!)