I have a coroutine with a repeat loop inside that checks the players distance from a part, if humanoid moved, or if the part depletes. Then in my other loop it keeps running until the coroutine is suspended. The problem is the coroutine suspends itself instantly. How do I fix this? I’m new to coroutines.
else
local mineSound = tool.mineRockSound
prompt.Enabled = false
miningAnimationTrack:Play()
local distanceCheckLoop = coroutine.create(function()
repeat
local distance = (humanoidRootPart.Position - prompt.Parent.Position).Magnitude
local proxDistance = prompt.MaxActivationDistance
wait()
until humanoid.MoveDirection.Magnitude > 0 or distance > proxDistance or hpValue.Value <= 0
end)
coroutine.resume(distanceCheckLoop)
while coroutine.status(distanceCheckLoop) == "running" do
local distance = (humanoidRootPart.Position - prompt.Parent.Position).Magnitude
local proxDistance = prompt.MaxActivationDistance
local mineSound = tool.mineRockSound
task.wait(0.85)
mineSound:Play()
task.wait(0.15)
hpValue.Value -= tool.damage.Value
print("did damage")
end
end
or is there a better way to detect that stuff so I can cancel animations/sounds/increments way quicker?
Thanks!