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

Why does this button get clicked when I don't click it?

Asked by 8 years ago
local currentgame = script.Parent.Parent.Parent
local menu = script.Parent
local play = script.Parent.Play
local quit = script.Parent.Quit
local upgrades = script.Parent.Upgrades
local quitmenu = script.Parent.Parent.Quit
local upgradesmenu = script.Parent.Parent.Upgrades
local gamemenu = script.Parent.Parent.Game

if currentgame.Visible == true then
    if play.MouseButton1Down then
        gamemenu.Visible = true
        menu.Visible = false
        print 'clicked play'
    end 
end

When I load my game, it prints "clicked play" in the output and loads the "gamemenu" screen, and I never even clicked the button? Help would be very much appreciated!

1 answer

Log in to vote
0
Answered by 8 years ago

This is because MouseButton1Down is not a boolean. A working way to do this would be to use MouseButton1Down as an event, because that's what it is.

currentgame = script.Parent.Parent.Parent -- all these don't need to be local, unless they are in a function or anf if statement or a loop.
menu = script.Parent
play = script.Parent.Play
quit = script.Parent.Quit
upgrades = script.Parent.Upgrades
quitmenu = script.Parent.Parent.Quit
upgradesmenu = script.Parent.Parent.Upgrades
gamemenu = script.Parent.Parent.Game

play.MouseButton1Down:connect(function()--eventy
    if currentgame.Visible then--no need for == true
        gamemenu.Visible = true
        menu.Visible = false
        print 'clicked play'--this stuff
    end
end)

I hope i helped!

0
Oh of course! I am dumb, learned a few things though, thanks!!!! :D UnknownGenerations 10 — 8y
0
Happy to help! ScriptsAhoy 202 — 8y
Ad

Answer this question