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

How do you use :wait() Instead of :connect()?

I saw the tip of the day yesterday and sadly forgot to read it, I would like to know how to make this code:

function Add(Num1, Num2)
	local Answer = Num1 + Num2
	print(Answer)
end


workspace.Baseplate.Touched:connect(function(Hit)
	local Human = Hit.Parent:FindFirstChild("Humanoid")
	if
		Human then
		Add(2,8)
	end
end)

Work with :wait() instead of connect() but so far all I have is:

workspace.Baseplate.Touched:wait(Add(2,8))

How would you add Hit and The Human variable? All help is appreciated.

3 comments

0

wait(number)

0

Why don't you just do workspace.Baseplate.Touched:connect(function() wait(2) Add(2,8) end)

1

Really guys... The "wait(int)" function and the "wait()" method of events is not the same thing. Plus, "connect()" and "wait()" have two completely different behaviors. lacikaturai was just asking about its usage, since it was the subject of a Tip Of The Day.

2 answers

✓ Accepted answer

It doesn't work like that. The function is better, this is an example of what you could do with that.

workspace.Baseplate.Touched:wait(2)
print("I waited 2 seconds!")

This'll print that in the output 2 seconds after the baseplate is touched. This pauses everything below it for how you specify.

4 comments

0

Why is this downvoted? Did I do something wrong?

1

Sorry. I'm a bit harsh with downvotes; a single misinformation is enough for me. I downvoted because unlike the 'wait()' function, you can't pass the amount of time as an argument to wait to an event's 'wait()' method. I probably should have commented instead.

0

Link is right. The wait() method has no arguments.

0

Ah, it's ok

wait and connect have two different behaviors and so are used for two different things.

connect passes a function to Roblox, which it can then call whenever the event is fired.

What waitreally does is pausing the execution of the current thread (or routine, if you prefer) until Roblox's scheduler decides to resume it (when the event is fired). wait is used when you only need to, well, wait, for the lack of a better word, for an event to occur once.

game.Workspace.Baseplate.Touched:wait()
print("Baseplate was touched once!")

So now, the print function will only be called once, after the Touched event of Baseplate is fired.

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