I am trying to make a fridge that opens a gui when you trigger a proximity prompt, and closes the gui when you press a button within the gui. The code I have will allow it to open and close once, but it won’t work multiple times. There are no errors that show up in the output window. Here is the code:
Open script:
local fridgePrompt = script.Parent.FridgePrompt
fridgePrompt.Triggered:Connect(function(plr)
local PlayerGui = plr:WaitForChild("PlayerGui")
local fridgeGui = PlayerGui.FridgeGUI.FridgeGUIFrame
fridgeGui.Visible = true
end)
Close script:
local button = script.Parent
local fridgeGui = button.Parent
local function closeFridgeGui()
fridgeGui.Visible = false
end
button.Activated:Connect(closeFridgeGui)
Try something like this for the prox prompt (script):
local fridgePrompt = script.Parent.FridgePrompt
local open = false
prompt.Triggered:Connect(function(player)
local PlayerGui = player:WaitForChild("PlayerGui")
local fridgeFrame = PlayerGui.FridgeGUI.FridgeGUIFrame
if open == false then
open = true
fridgeFrame.Visible = true
else
open = false
fridgeFrame.Visible = false
end
end)
Then for the close button (local script):
local player = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
player.PlayerGui.FridgeGUI.FridgeGUIFrame = false
end)
You’re setting the player’s gui’s visibility to true from the server and to false from the client, that change made by the client won’t replicate to the server so from the server’s perspective the gui is visible even if it was set to invisible by the client.
You can either use a RemoteEvent instance to circumvent your issue (which I recommend) or do the following.
fridgePrompt.Triggered:Connect(function(plr)
local PlayerGui = plr:WaitForChild("PlayerGui")
local fridgeGui = PlayerGui.FridgeGUI.FridgeGUIFrame
fridgeGui.Visible = false
fridgeGui.Visible = true
end)