RobloxScripterAI
Discord ↗
Link Copied to Clipboard
×
"npc that follows closest player walk animation and tell me where script goes"
-- server script (ServerScriptService) local npc = game.Workspace.NPC local pfs = game:GetService("PathfindingService") local players = game:GetService("Players") while true do local closestPlayer = nil local closestDistance = math.huge for _, player in ipairs(players:GetPlayers()) do if player.Character and player.Character.PrimaryPart then local distance = (npc.HumanoidRootPart.Position - player.Character.PrimaryPart.Position).magnitude if distance < closestDistance then closestDistance = distance closestPlayer = player end end end if closestPlayer and closestPlayer.Character and closestPlayer.Character.PrimaryPart then local path = pfs:CreatePath() path:ComputeAsync(npc.HumanoidRootPart.Position, closestPlayer.Character.PrimaryPart.Position) local waypoints = path:GetWaypoints() for _, waypoint in ipairs(waypoints) do npc.Humanoid:MoveTo(waypoint.Position) npc.Humanoid.MoveToFinished:Wait() end end wait(1) end -- The script should be placed in ServerScriptService in Roblox Studio. The NPC should be a Model with a Humanoid and HumanoidRootPart inside it, located in Workspace.