RobloxScripterAI
Discord ↗
Link Copied to Clipboard
×
"npc that follows closest player walk animation and tell me where script goes"
Here's a script for an NPC that follows the closest player using walk animation. This script should be placed in a Server Script under the NPC model. ```lua local NPC = script.Parent local humanoid = NPC.Humanoid local walkAnim = Instance.new("Animation") walkAnim.AnimationId = "rbxassetid://YourAnimationIDHere" -- Replace with your walk animation ID local walkTrack = humanoid:LoadAnimation(walkAnim) local PathfindingService = game:GetService("PathfindingService") local Players = game:GetService("Players") local function findClosestPlayer() local closestPlayer = nil local closestDistance = math.huge for _, player in ipairs(Players:GetPlayers()) do local character = player.Character if character then local distance = (character.HumanoidRootPart.Position - NPC.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 then local character = closestPlayer.Character if character then local path = PathfindingService:CreatePath() path:ComputeAsync(NPC.HumanoidRootPart.Position, character.HumanoidRootPart.Position) local waypoints = path:GetWaypoints() for _, waypoint in ipairs(waypoints) do humanoid:MoveTo(waypoint.Position) walkTrack:Play() humanoid.MoveToFinished:Wait() end end end wait(1) end ``` Make sure to replace "YourAnimationIDHere" with the actual ID of your walk animation.