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

How do I delay a script until an event fires?

I'm trying to delay action in a script until an event fires.

This is what I have

	local Capturing = script.Parent.Capturing
	Capturing.Changed:connect(function(property)
		if property == false then
			
		end
	end)

Capturing is a BoolValue, part of the same model as the script btw. When ran, it completely skips over the event handler

Would I have to repeat wait() until the property == false, or can I use this in some way?

2 comments

1

If you're waiting until the event is fired before doing some code, why not just put that code INSIDE the event?

0

Because its not as simple as that. I need to halt a function from ending.

1 answer

✓ Accepted answer

You're on the right track. Using the repeat until loop will help us here.

We can use a boolean variable to make sure an event is fired before continuing.

local Capturing = script.Parent.Capturing
local captured = false

Capturing.Changed:connect(function(property)
    if property then
		-- event related actions here
		-- has to be before captured = true
		captured = true
    end
end)

repeat wait() until captured
-- continue

1 comment

0

Thanks! Helps a lot.

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