They turn each second and then continue till the end
Here should be the full script:
local serverStorage = game:GetService("ServerStorage")
local mob = {}
function mob.Move(enemy, map)
local humanoid = enemy.Humanoid
local waypoints = map.WayPoints
for waypoint=1, #waypoints:GetChildren() do
humanoid:MoveTo(waypoints[waypoint].Position)
humanoid.MoveToFinished:Wait()
end
end
function mob.Spawn(enemyTy, quantity, sDelay, map)
for i=1, quantity do
local enemyExists = serverStorage.Enemies:FindFirstChild(enemyTy)
if enemyExists then
task.wait(sDelay)
local newEnemy = enemyExists:Clone()
newEnemy.HumanoidRootPart.CFrame = map.Start.CFrame
newEnemy.Parent = workspace.Enemies
coroutine.wrap(mob.Move)(newEnemy, map)
else
warn("There is no existing:"..enemyTy.."(Error: Enemy does not exist)")
end
end
end
return mob
Use HumanoidRootPart, it does the same thing, yet it can be more reliable in instances or set the Primary CFrame of the object(s) to a position.
You should probably switch from MoveToFinished to a Heartbeat repeat loop.
repeat
game:GetService("RunService").Heartbeat:Wait()
until (enemy.HumanoidRootPart.Position - waypoints[waypoint].Position).Magnitude <= 5
This works with magnitude, so I recommend putting the waypoints as close as possible to the ground so the Y axis doesn’t affect it. There’s an easy way to fix it but you can just put the waypoints on the ground instead.
How would I come to using it? Like HumanoidRootPart:MoveTo()
They don’t move at all? -------
They move but then they stop for some unknown reason. There is still no errors in the console.
I’d try changing the direction they’re moving to inside the repeat loop, this way you can make sure they will always try to go towards the waypoint.
repeat
game:GetService("RunService").Heartbeat:Wait()
humanoid:MoveTo(waypoints[waypoint].Position)
until (enemy.HumanoidRootPart.Position - waypoints[waypoint].Position).Magnitude <= 5
They now skip differently:
robloxapp-20211220-1857142.wmv (2.7 MB)
But I still dosen’t work
Edit: I will try mess around with magnitude
Lower the amount of magnitude. Instead of 5 put, I don’t know, 2 or 3?
Also another tip I can give is to add invisible walls around the paths so they cannot get out of them.
Would decimal magnitude values work because it nearly works
Yes you can use decimals if you want.
completely unrelated question if mods won’t remove this: what’s the difference between ipairs and pairs?
I am just going to report this as a bug as no one can fix this
It’s not a bug. Just an issue with ur script.
I feel like it’s a bug cause I was messing around with :MoveTo() and it seems like it is beacsue I made a whole new script and put it into to the enemy. The script it is:
local enemy = script.Parent
enemy.Humanoid:MoveTo(workspace.End.Position)
And it still does not go the full way. I have not used free models or anything it just does that by itself. I can show you proof here:
robloxapp-20211222-1348120.wmv (2.0 MB)
I’m actually gonna think that it’s a problem with the script instead. I think your MoveTo mechanism works perfectly, but the points are not ordered at all making them move to another point that they’re not intended to.
Here’s an example I just made using waypoints in a folder and just simply moving to each one.
Code Example
for _, part in pairs(workspace.Folder:GetChildren()) do
rigHumanoid:MoveTo(part.Position)
rigHumanoid.MoveToFinished:Wait()
end
As you can see, the script works. But the logic is still not complete. Although it seems like its skipping, there’s no script determining which waypoint to move to FIRST, having the engine just order by itself.
There are two ways you can do this.
Order by distance
table.sort(waypoints, function(a, b)
local aDistance = (a.Position - rigHumanoid.RootPart.Position).magnitude
local bDistance = (b.Position - rigHumanoid.RootPart.Position).magnitude
return aDistance < bDistance
end)
for _, part in pairs(waypoints) do
rig.Humanoid:MoveTo(part.Position)
rig.Humanoid.MoveToFinished:Wait()
end
This works very well, but you can see flaws that it could still ‘skip’ because one waypoint is actually closer than the other.
Order by number
table.sort(waypoints, function(a, b)
return tonumber(a.Name) < tonumber(b.Name)
end)
for _, part in pairs(waypoints) do
rig.Humanoid:MoveTo(part.Position)
rig.Humanoid.MoveToFinished:Wait()
end
This works just as well as the first one, but it is ideal if you want it to walk in a specific path, being the perfect method that can be utilized for the game.
I will attach a place file of this game that shows how each method works, you can find the script inside of the Dummy in the workspace.
Movement Example.rbxl (32.6 KB)
Try numbering your waypoints from closest to furthest (1 to x) and use this in your script and see how it works;
function mob.Move(enemy, map)
local humanoid = enemy.Humanoid
local waypoints = map.WayPoints:GetChildren()
table.sort(waypoints, function(a, b)
return tonumber(a.Name) < tonumber(b.Name)
end)
for _, waypoint in pairs(waypoints) do
humanoid:MoveTo(waypoints[waypoint].Position)
humanoid.MoveToFinished:Wait()
end
end
Mark as solution if this helped you! A little off topic; but a very cool project you’re making. I wish the best of luck
I just found out it’s not a bug not a problem with my script. Roblox set an 8 second timeout on :MoveTo()
. But thank you for trying to help me
hehe it’s time to use the good old position magnitude again