I am making a simple simulator game that has enemy’s that you can kill in order to gain EXP and Money. Problem is, Pathfinding Service is slow, and when I try to find a solution so that the pathfinding is smooth, its broken a different way. I am a new relatively new scripter but am pretty decent where I’m at.
Here in this video it shows how delayed the enemy is, I cannot find a solution for this and am seeking help. Video: https://gyazo.com/dc0d67a904cb9c64f7737ee8bde834a2
local pathFinding = game:GetService("PathfindingService")
local humanoid = script.Parent.Humanoid
local torso = script.Parent.UpperTorso
local FollowHB = script.Parent.Hitbox
local plrIsInHB = false
local zone = require(game.ReplicatedStorage.Modules.Zone)
local container = zone.new(FollowHB)
container.playerEntered:Connect(function(plr)
plrIsInHB = true
while true do
if plrIsInHB == true then
local currPath = pathFinding:CreatePath()
currPath:ComputeAsync(torso.Position, plr.Character.Torso.Position)
local waypoints = currPath:GetWaypoints()
for i, waypoint in ipairs(waypoints) do
if waypoint.Action == Enum.PathWaypointAction.Jump then
humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
end
humanoid:MoveTo(waypoint.Position)
humanoid.MoveToFinished:Wait()
if plrIsInHB == false then
local currPath = pathFinding:CreatePath()
currPath:ComputeAsync(torso.Position, workspace.StationaryPos1.Position)
local waypoints = currPath:GetWaypoints()
for i, waypoint in ipairs(waypoints) do
if waypoint.Action == Enum.PathWaypointAction.Jump then
humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
end
humanoid:MoveTo(waypoint.Position)
humanoid.MoveToFinished:Wait(.01)
end
break
end
end
end
task.wait(.008)
end
end)
container.playerExited:Connect(function(plr)
plrIsInHB = false
end)
Above this is my current code, I have tried this without the humanoid.MoveToFinished:wait(), although that fixes the delaying issue it jumps sporadically and I don’t know why. I could add a debounce to the jumping but i wanna know if there’s an alternative
Video: https://gyazo.com/a5db661e3c4d8244d17b6e191762590e