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

does moveTo and moveToFinished work with slower walk speeds?

Asked by 6 years ago

I created a while loop that has my npc walk a path back and forth. this path consists of 4 points.

It works fine when i have the npc walkspeed at 16, even if i stand in front of him and delay him to his point he keeps fighting until he gets to that point and then moves to the next one.

However, when i change the speed to 8 he starts walking towards the first point and before he even gets there he starts moving to the second and so on.

here is the code. the script is in the npc model

local humanoid = script.Parent.Humanoid
while wait() do
    humanoid:MoveTo(game.Workspace.wg1.pos1.Position)
    humanoid.MoveToFinished:Wait()

    humanoid:MoveTo(game.Workspace.wg1.pos2.Position)
    humanoid.MoveToFinished:Wait()

    humanoid:MoveTo(game.Workspace.wg1.pos3.Position)
    humanoid.MoveToFinished:Wait()

    humanoid:MoveTo(game.Workspace.wg1.pos4.Position)
    humanoid.MoveToFinished:Wait()

    humanoid:MoveTo(game.Workspace.wg1.pos3.Position)
    humanoid.MoveToFinished:Wait()

    humanoid:MoveTo(game.Workspace.wg1.pos2.Position)
    humanoid.MoveToFinished:Wait()

end

0
Same goes for me. When i changed the hum walkspeed to something lower than 16 it usually turns to the next pos before reaching it's destination iMazariuz 36 — 3y

1 answer

Log in to vote
0
Answered by
EB8699 30
6 years ago

I've written a GuardScript myself, it needs a Ton of optimization still but the patrol script might interest you:

--Patrol function
local function DoPatrol()
    while Patrolling == true do
        for i, v in pairs(Points) do
            if string.find(v.Name, "Point" .. tostring(CurrentPoint)) then
                Guard.Humanoid:MoveTo(v.Position)
                local Reached = nil
                spawn(function()
                    local Count = 5
                    for i = 1, Count * 2 do
                        if time() - LastPoint > Count then
                            Guard.Torso.CFrame = v.CFrame + Vector3.new(0, 2, 0)
                            break
                        elseif Reached ~= nil then
                            break
                        end
                        wait(0.5)
                    end
                end)
                Guard.Humanoid.MoveToFinished:wait()
                Reached = true
                LastPoint = time()
                DoPoint()
                DetectPlayer()
                wait(Delay)
            end
        end
        wait(0.1)
    end
end

I've tried moving the points, changing the walkspeed, removing the auto-teleport if a certain amount of time has passed and it hasn't reached the goal.

It all worked fine.

Tried your script as well, worked fine too.

Although I did notice that if you move the points, it will still go to the old position first if it's already heading there, else it'll refresh when it starts heading to it. Also noticed that if you are dragging the point it will skip it, probably because it can't detect it while it's being dragged.

So from what I can figure out, it's either lag or the parts are being moved too quickly for it to catch up.

Might need more information about what exactly is happening if the parts aren't being moved and it's not lagging.

(Sidenote, might I ask why you are still using game.Workspace when you can simply do workspace? I'd like to know which one is the deprecated version as I can't remember).

Ad

Answer this question