RobloxScripterAI
Discord ↗
Link Copied to Clipboard
×
"npc that follows closest player walk animation"
-- server script local pfs = game:GetService("PathfindingService") local npc = game.Workspace.NPC local walkAnimation = Instance.new("Animation") walkAnimation.AnimationId = "rbxassetid://507770453" -- Roblox walk animation ID local function findClosestPlayer() local closestPlayer = nil local closestDistance = math.huge for _, player in ipairs(game.Players:GetPlayers()) do if player.Character then local distance = (npc.HumanoidRootPart.Position - player.Character.HumanoidRootPart.Position).Magnitude if distance < closestDistance then closestDistance = distance closestPlayer = player end end end return closestPlayer end while true do local closestPlayer = findClosestPlayer() if closestPlayer and closestPlayer.Character then local path = pfs:CreatePath() path:ComputeAsync(npc.HumanoidRootPart.Position, closestPlayer.Character.HumanoidRootPart.Position) local waypoints = path:GetWaypoints() local humanoid = npc.Humanoid local walkAnimTrack = humanoid:LoadAnimation(walkAnimation) for _, waypoint in ipairs(waypoints) do humanoid:MoveTo(waypoint.Position) walkAnimTrack:Play() humanoid.MoveToFinished:Wait() end end wait(1) end