My ai is broken and my output says that

"local teddy = script.Parent
local humanoid = teddy.Humanoid
teddy.PrimaryPart:SetNetworkOwner(nil)

local function canSeeTarget(target)
local origin = teddy.HumanoidRootPart.Position
local direction = (target.HumanoidRootPart.Position - teddy.HumanoidRootPart.Position).unit * 230
local ray = Ray.new(origin, direction)

local hit, pos = workspace:FindPartOnRay(ray, teddy)


if hit then
	if hit:IsDescendantOf(target) then
		return true
	end
else
	return false
end

end

local function findTarget()
local players = game.Players:GetPlayers()
local maxDistance = 390
local nearestTarget

for index, player in pairs(players) do
	if player.Character then
		local target = player.Character
		local distance = (teddy.HumanoidRootPart.Position - target.HumanoidRootPart.Position).Magnitude
		
		if distance < maxDistance and canSeeTarget(target) then
			nearestTarget = target
			maxDistance = distance
		end
	end
end

return nearestTarget

end

local function getPath(destination)
local PathfindingService = game:GetService(“PathfindingService”)

local pathParams = {
	["AgentHeight"] = 15,
	["AgentRadius"] = 4,
	["AgentCanJump"] = false
}

local path = PathfindingService:CreatePath(pathParams)

path:ComputeAsync(teddy.HumanoidRootPart.Position, destination.Position)

return path

end

local function attack(target)
local distance = (teddy.HumanoidRootPart.Position - target.HumanoidRootPart.Position).Magnitude

if distance > 7 then
	humanoid:MoveTo(target.HumanoidRootPart.Position)
else
	local attackAnim = humanoid:LoadAnimation(script.Attack)
	attackAnim:Play()
	target.Humanoid.Health = 0
end

end

local function walkTo(destination)

local path = getPath(destination)

if path.Status == Enum.PathStatus.Success then
	for index, waypoint in pairs(path:GetWaypoints()) do
		local target = findTarget()
		if target and target.Humanoid.Health > 0 then
			attack(target)
			break
		else
			humanoid:MoveTo(waypoint.Position)
			humanoid.MoveToFinished:Wait()
		end
	end
else
	humanoid:MoveTo(destination.Position - (teddy.HumanoidRootPart.CFrame.LookVector * 10))
end

end

function patrol()
local waypoints = workspace.waypoints3:GetChildren()
local randomNum = math.random(1, #waypoints)
walkTo(waypoints[randomNum])
end

while wait(0.1) do
patrol()
end"

Make sure that you set the PrimaryPart property on the character model for whatever character you’re using the AI on.

I did and it’s to the humanrootpart

Your code is completely unreadable. Format it properly. Avoid taking just a picture of your screen from the phone and sending thinking people magically will know what you want to make.

I only took a picture of the output that’s it

Thats the problem. You can’t just send a pic of the output. You need to send your script and describe your issue. Your script needs to be formatted which its not. You just said your ai is broken nothing else, you didnt even tell what you expect.

--scripts should be formatted like this
1 Like

on the botton it says something about primary part and its connected to the PrimaryRootPart like it should and the ai keeps running into the wall and aint working right but when i copy and paste it into a new baseplate world it works fine