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

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

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

✓ Accepted answer

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)

2 comments

0

onButton1Down is the name of the function he is calling... -_-

0

Thanks! It worked! I had to fix a little mistake, but otherwise you did it perfectly!

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)

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