I want to make it so it touches the Block before changing direction, It works normally if the distance isn’t too far, but if the part is far and then you try it, it won’t reach it and will change even before.
The script should auto touch the brick then change, But its like its ignoring it.
Heres the Code:
local char = script.Parent
local humanoid = char.Humanoid
local pointA = script.Parent.Destinations.PointA
local pointB = script.Parent.Destinations.PointB
local pointC = script.Parent.Destinations.PointC
local pointD = script.Parent.Destinations.PointD
local nextDestinationObject = pointA
while wait(time) do
humanoid:MoveTo(nextDestinationObject.Position)
humanoid.MoveToFinished:Wait()
if nextDestinationObject == pointA then
nextDestinationObject = pointB
elseif nextDestinationObject == pointB then
nextDestinationObject = pointC
elseif nextDestinationObject == pointC then
nextDestinationObject = pointD
elseif nextDestinationObject == pointD then
nextDestinationObject = pointA
end
end```
In the documentation for this function it gives the reason for the error
The reach goal state of a humanoid will timeout after 8 seconds if it doesn’t reach its goal. This is done so that NPCs won’t get stuck waiting for Humanoid.MoveToFinished to fire. If you don’t want this to happen, you should repeatedly call MoveTo so that the timeout will keep resetting.
I’m pretty confused on how to set it up on the actual portion of it tho, Or rather get it to continue I mean. Inserting that code and even connecting it still disconnects before reaching it.
local character = script.Parent
local humanoid = character.Humanoid
local targets = {
script.Parent.Destinations.PointA,
script.Parent.Destinations.PointB,
script.Parent.Destinations.PointC,
script.Parent.Destinations.PointD
}
local currentTarget = 1
while wait(7) do
humanoid:MoveTo(targets[currentTarget])
end
humanoid.MoveToFinished:Connect(function()
currentTarget = (currentTarget + 1) % #targets + 1 --Resets the target count after it has reached all targets
humanoid:MoveTo(targets[currentTarget]) --So it doesn't wait for the 7 second loop to finish before starting to move again
end)
And I wasn’t able to test this, so hopefully there are no errors.