Robot Companion keeps stopping and more

So I’ve been testing things for hours and I still can’t figure out. So basically the Robot keeps, stopping
and when it’s near a wall or player it twitches I’ve been trying to figure out how to use something besides MoveToFinsh:Wait() because I think that’s why the Robot keeps stopping and I’ve been trying to use Connect() and Disconnect() but I can’t figure out where they go in the script to get no errors. I really would appreciate some help. This is my code, well only the Part I’m stuck on:
if Kadenogi and Robot then
local PathParam = {
[“AgentRadius”] = 3,
[“AgentHeight”] = 5,
[“AgentCanJump”] = true
}

local Destination = Kadenogi.HumanoidRootPart.Position + Vector3.new(-3.5,0,4.5)
local Follower = Robot.HumanoidRootPart.Position

local RobotRoot = game.Workspace.Ellaza:FindFirstChild("HumanoidRootPart")
local Length = 1

local RayThing = Ray.new(RobotRoot.Position, RobotRoot.CFrame.LookVector * Length)
local RayCastParams = RaycastParams.new()
RayCastParams.FilterDescendantsInstances = {game.Workspace.BaseOwner.BaseExtras:FindFirstChild("ForceField"), Players}
RayCastParams.IgnoreWater = true

if Robot and Kadenogi then

	local Path = game:GetService("PathfindingService"):CreatePath(PathParam)

	Path:ComputeAsync(Follower, Destination)

	local function Connection(Destination)
		if Path.Status == Enum.PathStatus.Success then
			for index, Waypoint in pairs(Path:GetWaypoints()) do
				Robot.Humanoid:MoveTo(Waypoint.Position)
				if RayThing then
					if RayCastParams then
						if Path.Blocked then
							Connection = Robot.Humanoid.MoveToFinished:Connect()
						end
					end
				end
			end
		end
	end
	Connection(Destination)
end

end

1 Like