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

Help With Function Issues?

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

✓ Accepted answer

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 comment

1

Spawn() is a better solution. Cor outlines are messy and I would never advise their use except for in certain situations.

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