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

Is there any way for a script to know exactly when a function connects?

Asked by 3 years ago
Edited 3 years ago

I'm trying to make a script that waits until a certain function fires. Is this possible?

Example of what i'm talking about:

repeat wait() until ManualTrigger:Connect()

Part = Instance.new("Part")
Part.Parent = game.Workspace

ManualTrigger = game.ReplicatedStorage.ManualTrigger.OnServerEvent:Connect(function()
       print("Fired")
end)

OR

spawn(function()
while true do
wait()
if ManualTrigger:Connect() then
print("ManualTrigger fired.")
end
end
end)

ManualTrigger = game.ReplicatedStorage.ManualTrigger.OnServerEvent:Connect(function()
       print("Fired")
end)

All help is appreciated.

1
game.ReplicatedStorage.ManualTrigger.OnServerEvent:Wait() ? Pupppy44 671 — 3y
0
^ just saying, that would yield the entire thread CaioAlpaca 342 — 3y

1 answer

Log in to vote
1
Answered by 3 years ago
Edited 3 years ago

You can make a variable and set it to true as soon as the event is fired, and make the loop wait until it's equal to true like this

local Fired = false

game.ReplicatedStorage.ManualTrigger.OnServerEvent:Connect(function()
       print("Fired")
    Fired = true
end)

repeat wait() until Fired == true

Part = Instance.new("Part")
Part.Parent = game.Workspace

0
I was considering using that beforehand, but like Pupppy44 said, I could also use game.ReplicatedStorage.ManualTrigger.OnServerEvent:Wait() which worked fine. I'll accept anyways ErskinePierre 48 — 3y
Ad

Answer this question