RobloxScripterAI
Discord ↗
Link Copied to Clipboard
×
"npc that follows closest player walk animation"
local ReplicatedStorage = game:GetService("ReplicatedStorage") local Players = game:GetService("Players") local NPC = ReplicatedStorage.NPC local function OnPlayerAdded(player) local npc = NPC:Clone() npc.Parent = workspace local humanoid = npc.Humanoid while true do local closestPlayer = nil local closestDistance = math.huge for _, otherPlayer in pairs(Players:GetPlayers()) do if otherPlayer ~= player then local distance = (otherPlayer.Character.PrimaryPart.Position - npc.PrimaryPart.Position).magnitude if distance < closestDistance then closestPlayer = otherPlayer closestDistance = distance end end end if closestPlayer then humanoid:MoveTo(closestPlayer.Character.PrimaryPart.Position) wait(0.1) end end end Players.PlayerAdded:Connect(OnPlayerAdded)