How do I make this script "Restart" itself?

Ok so, What I am trying to do is make a TextLabel be replaced by another TextLabel when a ImageButton is pushed, with the full frame closing when the button is pushed after the final TextLabel is visible and there is nothing else to replace it with (The Frame is opened through a ProximityPrompt). The script works but it only works once and can’t be done if you reopen it. The closest I’ve gotten is changing it so that it changes the Text instead of opening a TextLabel every time, which works as well but it still suffers the same issue where it can only be done once.

local Dialogue1 = script.Parent.Parent.Start
local Dialogue2 = script.Parent.Parent.Section1
script.Parent.MouseButton1Click:Connect(function()
	Dialogue1.Visible = false
	Dialogue2.Visible = true
	if Dialogue2.Visible == true then
		script.Parent.MouseButton1Click:Connect(function()
				Dialogue1.Visible = true
	Dialogue2.Visible = false
			script.Parent.Parent.Visible = false
			if script.Parent.Parent.Visible == false then
				Dialogue1.Visible = true
				Dialogue2.Visible = false
			end
		end)
	end	
end)

The script (LocalScript) is inside of the ImageButton being clicked btw

a

What you can do is use an Object Value, I use object values because they are easy to set up for my customers, and they are of great use, you can detect when an object value’s value changes and this allows you to update your script every time it changes. Of course, you need to make the script update the value of the object value so that it works

Why’re you setting Dialogue2 to true then checking if it’s true? It’ll always be true.

Then you have a nested event that is the same event. I’m not even sure what happens in that case.

I’d get rid of the inner duplicate event, and redo your logic to make things a lot cleaner. I haven’t tested this code at all, but something like this:

local Dialogue1 = script.Parent.Parent.Start
local Dialogue2 = script.Parent.Parent.Section1
script.Parent.MouseButton1Click:Connect(function()
	Dialogue2.Visible = not Dialogue2.Visible
	Dialogue1.Visible = not Dialogue2.Visible
	script.Parent.Parent.Visible = not Dialogue2.Visible
end)

By using the not logical operator you can replace the function of many conditional statements, I guess working this way mainly because your variables are really just dependent on Dialogue2’s value, which’ll either be true or false at any point—convenient for use with logical operators that work with boolean values.

EDIT: Here’s what I’m pretty sure is the equivalent of that code using conditional statements Perhaps you’d prefer this code for readability and/or ease of changing the code to support more conditions:

local Dialogue1 = script.Parent.Parent.Start
local Dialogue2 = script.Parent.Parent.Section1
script.Parent.MouseButton1Click:Connect(function()
	if Dialogue2.Visible == false
		Dialogue2.Visible = true
		Dialogue1.Visible = false
		script.Parent.Parent.Visible = false
	else
		Dialogue2.Visible = false
		Dialogue1.Visible = true
		script.Parent.Parent.Visible = true
	end
end)
3 Likes