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

Help With Function Issues?

Asked by
Scootakip 299 Moderation Voter
9 years ago
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.

1 answer

Log in to vote
1
Answered by
4Bros 550 Moderation Voter
9 years ago

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
1
Spawn() is a better solution. Cor outlines are messy and I would never advise their use except for in certain situations. User#6546 35 — 9y
Ad

Answer this question