Pausing a Script until event triggered

I’m trying to pause my UserInputService until the event is triggered.

Here’s my script.

local UIS = game:GetService("UserInputService")
local storyChat = {"I need to you solve a couple of cases for me. Some are pretty hard.", "Our first task is getting this door open. There's a keypad over there. Must be a pin of some type.", "I was left with a hint: The fool doth think he is wise, but the wise man knows himself to be a fool.","Congrats, you opened the door."}
local dialog = 1
local event1 = game.ReplicatedStorage:WaitForChild("Correct1")
UIS.InputEnded:Connect(function(input,gpe)
	if gpe then
		return
	end
	if input.KeyCode == Enum.KeyCode.Return then
		local input = input.KeyCode == Enum.KeyCode.Return 
		if input then
			script.Parent.Text = storyChat[dialog + 1]dialog += 1
			print(dialog)
			if dialog == 3 then
				local frame = script.Parent.Parent
				script.Parent.Parent.Size = UDim2.new(0.222, 0,0.31, 0)
				frame:TweenPosition(
					UDim2.new(0, 0,0.435, 0),
					"Out",
					"Quad",
					5,
					true
				)
				event1.OnClientEvent:Wait()
			end
		end
	end
	
end)

If someone could help, that would be great.

Debounce is your friend.

local UIS = game:GetService("UserInputService")
local d = false
local storyChat = {"I need to you solve a couple of cases for me. Some are pretty hard.", "Our first task is getting this door open. There's a keypad over there. Must be a pin of some type.", "I was left with a hint: The fool doth think he is wise, but the wise man knows himself to be a fool.","Congrats, you opened the door."}
local dialog = 1
local event1 = game.ReplicatedStorage:WaitForChild("Correct1")
UIS.InputEnded:Connect(function(input,gpe)
	if gpe then
		return
	end
	if input.KeyCode == Enum.KeyCode.Return then
		local input = input.KeyCode == Enum.KeyCode.Return 
		if input and not d then
            d = true
			script.Parent.Text = storyChat[dialog + 1]dialog += 1
			print(dialog)
			if dialog == 3 then
				local frame = script.Parent.Parent
				script.Parent.Parent.Size = UDim2.new(0.222, 0,0.31, 0)
				frame:TweenPosition(
					UDim2.new(0, 0,0.435, 0),
					"Out",
					"Quad",
					5,
					true
				)
				event1.OnClientEvent:Wait()
			end
            d = false
		end
	end
	
end)

what are you using to pause the script?

dialog or something else? tell me if its a dialog

Totally forgot about debounce. Now, would I enable debounce from the event or?

From the event instead of the if input would be preferable too to reduce script usage.

Could you give me an example of this?

local UIS = game:GetService("UserInputService")
local d = false
local storyChat = {"I need to you solve a couple of cases for me. Some are pretty hard.", "Our first task is getting this door open. There's a keypad over there. Must be a pin of some type.", "I was left with a hint: The fool doth think he is wise, but the wise man knows himself to be a fool.","Congrats, you opened the door."}
local dialog = 1
local event1 = game.ReplicatedStorage:WaitForChild("Correct1")
UIS.InputEnded:Connect(function(input,gpe)
	if gpe then
		return
	end
	if input.KeyCode == Enum.KeyCode.Return and not d then
        d = true
			script.Parent.Text = storyChat[dialog + 1]dialog += 1
			print(dialog)
			if dialog == 3 then
				local frame = script.Parent.Parent
				script.Parent.Parent.Size = UDim2.new(0.222, 0,0.31, 0)
				frame:TweenPosition(
					UDim2.new(0, 0,0.435, 0),
					"Out",
					"Quad",
					5,
					true
				)
				event1.OnClientEvent:Wait()
		end
        d = false
	end
	
end)

Yea, I got that. I remember debounce. How would I make the event reactivate debounce?

What do you mean?? it’s already there at the end d = false

Okay, so it has to work. I totally forgot a local script cant send a remote event to another local script.