#MoveTo command skipping parts

1 messages · Page 1 of 1 (latest)

tropic jewel
#

Hi, I'm trying to make this humanoid walk for my strategy game but it keeps skipping this red part on the turn. Right when its about to touch it it just skips to the part after the turn. It also doesnt touch the final part. Code, workspace and bug is all in the video.

#

sending mp4 so u can watch on discord...

jagged zodiac
#

Maybe try moving the unit a few studs further in the direction of the current waypoint? I never tried something like this so its just an idea.

tropic jewel
#

how do ı do that exactly?

jagged zodiac
#

I think there is another inbuild function called Humanoid:Move() which should just move the character forward.

#

Im not home right now so I can't really check

tropic jewel
#

Feels too manual, ı'm gonna try pathfinding instead

#

thanks though

jagged zodiac
#

alr gl

junior glade
tropic jewel
#

it still cant turn properly though

#


local pfs = game:GetService("PathfindingService")

local unit = script.Parent
local humanoid = unit.Humanoid
local hrp = unit.HumanoidRootPart
local range = unit.Range
local found = 0


local path = pfs:CreatePath({
})

path:ComputeAsync(hrp.Position, workspace.EndPoint.Position)

if path.Status == Enum.PathStatus.Success then
    local waypoints = path:GetWaypoints()
    
    for i, waypoint in waypoints do
        local p = Instance.new("Part", workspace)
        p.Position = waypoint.Position
        p.Anchored = true
        p.Material = Enum.Material.Neon
        p.CanCollide = false
        p.Size = Vector3.new(1,1,1)
    
    end
end


if path.Status == Enum.PathStatus.Success then
    local waypoints = path:GetWaypoints()

    for i, waypoint in waypoints do
        print("loop starting")
        while found == 0 do
            humanoid:MoveTo(waypoint.Position)
            humanoid.MoveToFinished:Wait()    
            range.Touched:Connect(function(man)
                if man.Parent:FindFirstChild("Range") then
                    found = 1
                end

            end)
        end
        


    end
end
junior glade
#

createpath is empty and you still have movetofinished:wait() in there

tropic jewel
#

I also tried to make it stop when it touches something called range but it just doesnt move now

junior glade
#

also there is no context to this code it appears to only run once

tropic jewel
#

when ı try to add anythig to the createpath for example

#

AgentCanJump = false

#

it straight up doesnt run

junior glade
#

follow the roblox docs example

#

make blank humanoid move between 2 parts doesn't have to be fancy, get that working with the roblox docs code

tropic jewel
#

ok, I'll try

junior glade
#

maybe put a part in the way to show it actually pathfinding when you got it moving

#

when you finished that, apply what you learned to your current code

junior glade
tropic jewel
#

this page is really long

#

how am I supposed to follow this? I'm looking at the example but i can hardly understand it

#

also, this page also uses movetofinished

junior glade
junior glade
junior glade
#

notice how it says MoveToFinished:Connect and not MoveToFinished:Wait Thumbs

#

and if it takes you more than a day to get through it, that's normal. code is not an overnight thing, it takes time

#

this is why game dev takes so long ;o

#

80% of scripting is actually reading code, not writing it.

tropic jewel
#

@junior glade I tried adding movetofinished:connect but I failed a bit

#

can you help?

#

it just goes to the final waypoint

#
local unit = script.parent
local waypoints = workspace.Waypoints


for waypoint=1, #waypoints:GetChildren() do
    unit.Humanoid:MoveTo(waypoints[waypoint].Position * Vector3.new(1,0,1))
    unit.Humanoid.MoveToFinished:Connect(function()
        waypoint =waypoint+1
    end)

end
--local pos = waypoints[waypoint].Position * Vector3.new(1,0,1)
junior glade
#

you cannot use the connection in the same way you would use movetofinished:wait() bruh

tropic jewel
#

Im sorry I'm just tryna learn I've never done game developing before

junior glade
#

actually it doesn't even go to the first one, it goes to all of them immediately, it just happens the last waypoint is the last time moveto is called so that takes priority

tropic jewel
#

oh

junior glade
#
    unit.Humanoid.MoveToFinished:Connect(function()
        waypoint =waypoint+1
    end)
``` and this does nothing. it's like you wrote this:
```lua
for i=1,100 do
  i += 1 -- what does this even mean bro
end```
tropic jewel
#

I'm sorry dude 😭

#

I was tryin to change

#

which waypoint it was going to

#

by +=1

junior glade
#

take a closer look at how the docs does it 👍

tropic jewel
#

the doc does it by pathfinding tho

#

would it matter?

tropic jewel
#

@junior glade I finally did it with movetofinished:connect but the problem is still happening. Its moving correctly to all the parts but its still not fully touchingthe turns and the one at the end

#
local unit = script.Parent
local humanoid = unit:FindFirstChild("Humanoid")
local waypoints = game.Workspace.Waypoints
local currentWaypoint = 1

humanoid.MoveToFinished:Connect(function(success)
    if success then
        currentWaypoint += 1
    end
    humanoid:MoveTo(waypoints[currentWaypoint].Position)
end)
humanoid:MoveTo(waypoints[currentWaypoint].Position)
#

I swear I got it right this time

junior glade
#

moveto times out after 8 seconds you didn't capture that situation. it's in the docs, you left it out

tropic jewel
#

wait

solar jasperBOT
#

studio** You are now Level 10! **studio

tropic jewel
#

just look at the video

junior glade
#

ya looks fine

#

keep going

#

keep fine-tuning it

#

if you want exact position at the end, make it move to exact position

tropic jewel
#

thats what I'm making it do

#

I'm making it moveot that waypoint