Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 6 years ago
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)


0
you are trying to do a mouse button click into a frame, you should use textbutton caipira 29 — 6y

1 answer

Log in to vote
0
Answered by
Azarth 3141 Moderation Voter Community Moderator
6 years ago
Edited 6 years ago

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)


Ad

Answer this question