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

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

Asked by 7 years ago

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.

0
wait(number) arrowman888 69 — 7y
0
Why don't you just do workspace.Baseplate.Touched:connect(function() wait(2) Add(2,8) end) tkddude2 75 — 7y
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. Link150 1355 — 7y

2 answers

Log in to vote
2
Answered by
itsJooJoo 195
7 years ago

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.

0
Why is this downvoted? Did I do something wrong? itsJooJoo 195 — 7y
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. Link150 1355 — 7y
0
Link is right. The wait() method has no arguments. Perci1 4988 — 7y
0
Ah, it's ok itsJooJoo 195 — 7y
Ad
Log in to vote
1
Answered by
Link150 1355 Badge of Merit Moderation Voter
7 years ago
Edited 7 years ago

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.

Answer this question