Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I delay a script until an event fires?

Asked by 8 years ago

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?

1
If you're waiting until the event is fired before doing some code, why not just put that code INSIDE the event? Perci1 4988 — 8y
0
Because its not as simple as that. I need to halt a function from ending. randomsmileyface 375 — 8y

1 answer

Log in to vote
1
Answered by
Lacryma 548 Moderation Voter
8 years ago

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
0
Thanks! Helps a lot. randomsmileyface 375 — 8y
Ad

Answer this question