MoveWater() wait(10) RT.WaterDoor.Transparency = 0
So I need help with this part of my script.
I need the wait(10)
to start immediately after MoveWater (Which is a function) is activated. The problem is, that it waits for MoveWater to finish (Which it takes a while to finish) before it starts to do the wait(10).
Is the problem that this is something Roblox does, or is it a problem with the function's code? Here's the function's code...
function MoveWater(part) for n = 0, MagWater, IncrementWater do WaterMover.CFrame = WaterMover.CFrame + (DirectionWater * IncrementWater) wait( (TimeWater/MagWater) * IncrementWater ) end end
If someone could help me with this it would be much appreciated.
Side note: The wait( (TimeWater/MagWater) * IncrementWater )
is necessary for the function to run properly.
Your answer to your problem is coroutines. Coroutines allow multiple threads to run alongside each other without having to create separate script instances or have to wait for the current running code block to finish (AKA you can execute separate functions asynchronously without having to wait for them to finish).
For more information regarding coroutines: http://wiki.roblox.com/index.php?title=Coroutines
coroutine.resume(coroutine.create(MoveWater)) -- coroutine.resume runs a coroutine, coroutine.create creates a new coroutine with the function MoveWater wait(10) RT.WaterDoor.Transparency = 0