AI is being wonky


code:

local pfs = game:GetService("PathfindingService")
local pathparams = {
	["AgentHeight"] = 6.5,
	["AgentRadius"] = 5,
	["AgentCanJump"] = false
}
local waypoints = {}
local goal = workspace.endpart
local waypointindex = 1
script.Parent.PrimaryPart:SetNetworkOwner(nil)
local torso = script.Parent:WaitForChild("Torso")
local humanoid = script.Parent:WaitForChild("Humanoid")
local root = script.Parent:WaitForChild("HumanoidRootPart")
local anim = script.Parent.JumpscareAnimation
local animation = humanoid:LoadAnimation(anim)
root.Touched:Connect(function(hit)
	local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
	if plr then
		script.Parent:WaitForChild("Jumpscare"):Play()
		animation:Play()
		root.CanTouch = false
		root.Anchored = true
		plr.Character:WaitForChild("Humanoid").WalkSpeed = 0
	 	plr.PlayerScripts:WaitForChild("RunningScript"):Destroy()
	end
end)
local path
local function Walk()
	script.Parent.PrimaryPart:SetNetworkOwner(nil)
path = pfs:CreatePath(pathparams)
	path:ComputeAsync(torso.Position, workspace.endpart.Position)
	if path.Status == Enum.PathStatus.Success then
		local waypoints = path:GetWaypoints()
		waypointindex = 2
		humanoid:MoveTo(waypoints[waypointindex].Position)
	end
	path.Blocked:Connect(function(blockedwaypointindex)
		if blockedwaypointindex > waypointindex then
			Walk()
		end
	end)
end
while task.wait() do
	Walk()
	end

It looks nice in my opinion!

Try changing the waypoint spacing of the agent parameters.

1 Like

how do i do that? it’s 1 part. i’m going to make the monster follow the humanoidrootpart of the player.

Add WaypointSpacing into your agent params and make it math.huge.

1 Like

frigging saver man. you solved both of my AI posts LOL.

i was about to say to SetNetworkOwner

i have it the function and in the script.