(Sorry if the answer is really simple, I’m a bit rusty in coding)
This:
for i, v in pairs(pathpoints) do
if i == 5 then
break
end
currentyeeyee.Value = i+1
hum:MoveTo(v.Position, v)
hum.MoveToFinished:Wait()
if inunderground.Value ~= true then
if (hrp.Position - v.Position).Magnitude > 1 and (hrp.Position - v.Position).Magnitude < (hrp.Position - (pathpoints[i]).Position).Magnitude then
hum:MoveTo(v.Position, v)
hum.MoveToFinished:Wait()
end
else
repeat task.wait()
until inunderground.Value == false
end
print("Loop iteration ended")
end
Is my for loop. It’s supposed to move to a specific place, and after the :Wait() is finished, it either
- repeats moving until it reaches its destination
or
- keeps waiting until inunderground.Value is false
However, the loop literally skips everything and prints loop iteration ended in less than 5 seconds. Why does this happen?
I dont really understand what your trying to do. But you should change this to.
repeat inunderground.GetPropertyChangedSignal("Value"):Wait() -- doesnt keep looping. waits for value to change
until inunderground.Value == false
1 Like
Why are you checking if i == 5?
when i turns to 5 the loop breaks so… yeah.
Boy, did that almost work…
if inunderground.Value ~= true then
if (hrp.Position - v.Position).Magnitude > 1 and (hrp.Position - v.Position).Magnitude < (hrp.Position - (pathpoints[i]).Position).Magnitude then
hum:MoveTo(v.Position, v)
hum.MoveToFinished:Wait()
end
else
repeat inunderground.GetPropertyChangedSignal("Value"):Wait()
until inunderground.Value == false
end
i is used for each items you check in pairs, so basically you assign +1 for each item, not for one. It’s hard to explain with my english, basically it’s like this
[1] item + 1
[2] item + 1
[3] item + 1
[4] item + 1
[5] item + 1
So what exactly are you suggesting I do? I don’t fully understand
why not loop like this?
for i = 1, math.min(5, #pathpoints) do
local v = pathpoints[i]
currentyeeyee.Value = i+1
hum:MoveTo(v.Position, v)
hum.MoveToFinished:Wait()
if inunderground.Value ~= true then
if (hrp.Position - v.Position).Magnitude > 1 and (hrp.Position - v.Position).Magnitude < (hrp.Position - (pathpoints[i]).Position).Magnitude then
hum:MoveTo(v.Position, v)
hum.MoveToFinished:Wait()
end
else
repeat task.wait()
until inunderground.Value == false
end
print("Loop iteration ended")
end
tried something like that, didn’t change a thing
After playtesting and messing around, I got what I wanted
The (temporary) solution was literally just
currentyeeyee.Value = i-2
a