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

Why does my GUI button script mess up with if statements?

script.Parent.MouseButton1Click:Connect(function() if game.Players.LocalPlayer.PlayerGui.Lazarun.TotemGUI.Visible = true then game.Players.LocalPlayer.PlayerGui.Lazarun.TotemGUI.Visible = false else game.Players.LocalPlayer.PlayerGui.Lazarun.TotemGUI.Visible = true end)

The idea here is that pressing the button on the player's GUI will open TotemGUI it if it's closed, and pressing the button while TotemGUI is open will close it. However the code currently returns "Incomplete statement: expected assignment or a function call" (I'm not sure what this means), I've heard that for if statements the = needs to be ==, but that also returns an error.

Which part am I messing up on? (Additionally, how do I put my code in a code block?)

1 answer

Your code:

script.Parent.MouseButton1Click:Connect(function()
if game.Players.LocalPlayer.PlayerGui.Lazarun.TotemGUI.Visible = true then -- put == not just one =
 game.Players.LocalPlayer.PlayerGui.Lazarun.TotemGUI.Visible = false
 else 
game.Players.LocalPlayer.PlayerGui.Lazarun.TotemGUI.Visible = true 
end) -- add another end

Edited code:

script.Parent.MouseButton1Click:Connect(function() -- click
        if game.Players.LocalPlayer.PlayerGui.Lazarun.TotemGUI.Visible == true then -- if visible
            game.Players.LocalPlayer.PlayerGui.Lazarun.TotemGUI.Visible = false -- make false
        else -- If not
            game.Players.LocalPlayer.PlayerGui.Lazarun.TotemGUI.Visible = true -- make true
        end -- second line
    end -- third line
)

To add a code block, you need to

paste your code, select your whole code. while your code is selected, click the Lua button, or the sixth button.

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