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

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

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.

2 comments

1

game.ReplicatedStorage.ManualTrigger.OnServerEvent:Wait() ?

0

^ just saying, that would yield the entire thread

1 answer

✓ Accepted answer

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

1 comment

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

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