What changes a simple task.wait to a system?

In my game there were some lines of pathfindingservice code, what happened was that in a part where there was a MoveTo() then a Task.wait, and at the end a MoveToFinished, not even the MoveTo() was executed, when I removed the Task.wait, worked correctly, what happened?

4 Likes

It would be very helpful to see the code honestly :smiley:

3 Likes

you put an uppercase T in task.wait(), that will error
from what i’ve seen, i cant tell anything else without seeing code

1 Like

No friend, I’m sorry, many people tell me the same thing and it’s not like that, I just said that there is that, but nothing is, I give the code and in the end, nobody helps me @TimeFrenzied, whoever knows knows and has no doubts when giving a simple answer , and the task.wait is lowercase, the output does not print any error, however it prints the prints that are,

for i , Point in pairs(Ruta:GetWaypoints) do 
hum:MoveTo(Point.Position)
task.wait()
if value > (torso.Position - Point.Position).Magnitude then
hum:MoveTo(Point.Position)
--never is executed
end
print("ok")
hum.MoveToFinished:Wait()
end
1 Like

why do you need the task.wait()? it’s already waiting until your moveto is finished, this is a stretch but since you’re yielding the movetofinished connection by a heartbeat, maybe it’s reaching the waypoint first? (very unlikely but the task.wait should be unneccecary anyway,) if you want a task.wait() then put it AFTER the movetofinished connection, try that

1 Like

As you can see, each Waypoint has a distance of 2 cues, therefore it is impossible for it to arrive in 0.03 seconds, also, when a movement ends or adds to the wait, therefore the last of your sentence is incorrect (I already modified the code to that you see why is the task.wait) and to @kwkxbxkdkdjjd provide the code and it didn’t help me

Try adding the task.wait after the movetofinished, maybe that’ll help?

1 Like

Yes, excuse me for not explaining, but I put that conditional to detect if there was no movement after the MoveTo() call, which repeated the call again, previously I did it in a loop and it didn’t work, and I think which was for the same reason, nobody and absolutely nobody helped me in the subject that I did, but hey, you know why I did the conditional and the task.wait() is there to give time to the call of the function
this is the topic: Why MoveTo() Not Working

1 Like

No, the code helped very pretty much. We can realise something here. Have you ever noticed that in your code there is an if statement?

if value > (torso.Position - Point.Position).Magnitude then
-- code
end

The “value” variable seemingly is not bigger and that’s the problem, not the task.wait().
What exactly “value” is, have you never described. It’s not like people don’t respond to you because they don’t want to help you. They either don’t know how to or you don’t provide enough information, just like in this case. Use the topic post template.

We can check if it’s actually the if statement causing this issue by troubleshooting.
Might you put a

print("check")

line under the task.wait() and then run the game and send a screenshot of the output?

1 Like

I have a few questions but I feel like we’re getting somewhere.

  1. Are you moving a player or an NPC?

Then it’s hard to understand how to solve this without more code, what is “value”
Also, you’re checking if the value is OVER the distance from the torso to the point, which will not run (and im pretty sure this can never even happen since yk, the torso can never be over its own position, but i could be wrong) since you JUST started moving to the torso, so it will not be over that distance. The if statement is causing the problem, just like the person above me mentioned. Instead try using:

  1. Humanoid.MoveDirection | If it’s over Vector3.zero then I think the humanoid is moving. So simply check if it’s Vector3.zero.

  2. Define the initial torso position and check if it moved in the direction of the point after the wait.

  3. Use the AssemblyLinearVelocity of the HumanoidRootPart

also, pathfinding should not have no movement but here might be some solutions
The stuff I mentioned SHOULD work, but if you have further problems mention me.

OLD BECAUSE OF NICOLAS MADURO’S MUSTACHES haha, you just saw that the conditional closes before the task.wait, I said in the topic that when I removed the task.wait it worked correctly, haha bro look well please haha

I found a different solution, and if you were right at the beginning

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.