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

Button changes, but doesn't change back? [RESOLVED]

Asked by 8 years ago

I'm trying to make a GUI button change to a certain text and change back, but it doesn't go back to the original text! (Fire Laser) There's no output errors.

tparent = script.Parent.Text
function onButton1Down()
    if tparent == "Fire Laser" then
        print("trowowsers")
        script.Parent.Text = "Stop Firing"
    else 
        script.Parent.Text = "Fire Laser"
        print("bowowser")
    end
end
script.Parent.MouseButton1Down:connect(onButton1Down)

Please help me!

2 answers

Log in to vote
0
Answered by 8 years ago

I would recommend using MouseButton1Click instead of onButton1Down, and here is what you can do differently.



script.Parent.MouseButton1Click:connect(function() if script.Parent.Text == "Fire Laser" then print("trowowsers") script.Parent.Text = "Stop Firing" elseif script.Parent.Text = "Stop Firing" script.Parent.Text = "Fire Laser" print("bowowser") end end)
0
onButton1Down is the name of the function he is calling... -_- M39a9am3R 3210 — 8y
0
Thanks! It worked! I had to fix a little mistake, but otherwise you did it perfectly! NobleReign 36 — 8y
Ad
Log in to vote
0
Answered by 8 years ago

Set tparent = script.Parent, not script.Parent.Text.

This will solve your problem!

tparent = script.Parent
function onButton1Down()
    if tparent.Text == "Fire Laser" then
        print("trowowsers")
        tparent.Text = "Stop Firing"
    else 
        tparent.Text = "Fire Laser"
        print("bowowser")
    end
end
script.Parent.MouseButton1Down:connect(onButton1Down)

Answer this question