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.
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.
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 wait
really 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.