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 9 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.

01tparent = script.Parent.Text
02function onButton1Down()
03    if tparent == "Fire Laser" then
04        print("trowowsers")
05        script.Parent.Text = "Stop Firing"
06    else
07        script.Parent.Text = "Fire Laser"
08        print("bowowser")
09    end
10end
11script.Parent.MouseButton1Down:connect(onButton1Down)

Please help me!

2 answers

Log in to vote
0
Answered by 9 years ago

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

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

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

This will solve your problem!

01tparent = script.Parent
02function onButton1Down()
03    if tparent.Text == "Fire Laser" then
04        print("trowowsers")
05        tparent.Text = "Stop Firing"
06    else
07        tparent.Text = "Fire Laser"
08        print("bowowser")
09    end
10end
11script.Parent.MouseButton1Down:connect(onButton1Down)

Answer this question