Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why doesn't my Visible = true/false not work?? (open/close gui)

Weapons = game.Players.LocalPlayer.PlayerGui.ScreenGui.Frame1.Weapons
Frame = game.Players.LocalPlayer.PlayerGui.ScreenGui.Frame

Weapons.MouseButton1Click:connect(function()
	if game.Players.LocalPlayer.PlayerGui.ScreenGui.Frame.Visible == false then
		game.Players.LocalPlayer.PlayerGui.ScreenGui.Frame.Visible = true else
		game.Players.LocalPlayer.PlayerGui.ScreenGui.Frame.Visible = false
	end
end)


1 comment

0

you are trying to do a mouse button click into a frame, you should use textbutton

1 answer

✓ Accepted answer

Start by indexing your variables before you need them. Doing so promotes better readability, functionality, and helps follow DRY (Don't Repeat Yourself). The best time to start writing clean code is from the start. Doing so promotes good habits you don't need to correct later. Check the output for errors.

Note: Wrote in a rush, need to leave, good luck!

-- Use local variable unless you actually need to be using global variables. 
-- Use a LocalScript and LocalPlayer
	-- You should be using a LocalScript already, since it's in your PlayerGui. 
-- Use the method WaitForChild() - online scripts can load before objects do

local player = game.Players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
local ScreenGui = playerGui:WaitForChild("ScreenGui") 
local Frame = ScreenGui:WaitForChild("Frame")
local Frame1 = ScreenGui:WaitForChild("Frame1")
local Weapons = Frame1:WaitForChild("Weapons") -- This needs to be a Button

-- Use 'C'onnect
Weapons.MouseButton1Down:Connect(function()
	Frame.Visible = not Frame.Visible -- Does the opposite of whatever it is
end)


This discussion is preserved as it was. New answers, comments, and votes are closed.