Click to continue just skipping over everything

speech.Activated:Connect(function()
	speechLabel.Text = 'Text 1'
	wait(2)
	speech.Activated:Connect(function()
		speechLabel.Text = 'Text 2.'
		camera.CameraSubject = cameraSheep
		camera.CFrame = CFrame.new(cameraSheep.Position)*CFrame.Angles(0, math.rad(140), 0)*CFrame.new(0, 10, 20)
		wait(2)
		speech.Activated:Connect(function()
			speechLabel.Text = 'Text 3'
			camera.CameraSubject = cameraTree
			camera.CFrame = CFrame.new(cameraTree.Position)*CFrame.Angles(0, math.rad(80), 0)*CFrame.new(0, 10, 20)
			wait(2)
			speech.Activated:Connect(function()
				speechLabel.Text = Text 4'
				camera.CameraSubject = cameraMetal
				camera.CFrame = CFrame.new(cameraMetal.Position)*CFrame.Angles(0, 0, 0)*CFrame.new(0, 0, 0)
				wait(2)
            end)
        end)
    end)
end)

Currently when you click it just skips all of this goes to the next section of the code. I basically want so whenever you click the button it goes to the next section of text.

1 Like

Never connect an event more than once. Unexpected things happen.
This isn’t the best or the cleanest way, but this is probably the easiest way to understand what I’m writing.

local debounce = false -- this is so you can't spam click it. It appeared that this is what you wanted.

speech.Activated:Connect(function()
	if debounce then
		debounce = false
		if SpeechLabel.Text == 'Text 1' then
			SpeechLabel.Text = 'Text 2'
		elseif SpeechLabel.Text == 'Text 2' then
			SpeechLabel.Text = 'Text 3'
		elseif SpeechLabel.Text == 'Text 3' then
			SpeechLabel.Text = 'Text 4'
		else
			SpeechLabel.Text = 'Text 5'
			camera.CameraSubject = cameraMetal
			camera.CFrame = CFrame.new(cameraMetal.Position)*CFrame.Angles(0, 0, 0)*CFrame.new(0, 0, 0)
		end
	end
end)
2 Likes

What does this mean at all? I’ve been connecting multiple connections to the same event thousands of times in the past decade and have had no issues that weren’t a result of my own code creating race conditions.

1 Like

I thought connecting the same event overwrites the previous connection?

No? Then it would be a callback, not a connection.

1 Like

If you’re confused, I think I have the proper explanation for you (sorry for going off-topic, OP).

When you use “connect”, you’re telling a function to listen to an RBXScriptSignal. This function will be run as in when it is called - an outside or so influence signals connected functions to run. Connecting to an event gives you an RBXScriptConnection object, which provides you a means to disconnect the method. So connecting to an event is like telling the backend “run this/these function/s when signaled”. Notice that you never set anything, you simply connect a function to an event.

In the case of callback, that is when you can only have one function connected and if connected later, the new function overwrites the previous one. That is because as opposed to an event, a callback is a variable with a nil value that needs to be defined. When you write something like ProcessReceipt = function or function Marketplace.ProcessReceipt, you’re setting the value of something. You can only have one value defined to a variable. Functions are values.

To summarize:
With events, you’re asking one or more functions to be ran when signaled.
With callbacks, you’re defining what function needs to be called when invoked.

Does this make sense?

It makes perfect sense. I actually understand callbacks more than I understand events, but whatever.
When I was learning scripting, I thought I discovered that you could only connect something once. I don’t know if it changed, or if I was just doing something wrong, but that’s where my idea stems from. Now, when I used to participate in the legacy forums, there were an awful lot of cases where people did things with multiple connections, much like the OP did. It became kind of a rule that you should never connect to the same event twice. My overall problem is I haven’t actually done development on Roblox for some time and I just hang around because I still thoroughly enjoy doing so and I care a lot about the future of Roblox - it just means things I say may not be up to snuff anymore. Thank you Allen.

1 Like