RobloxScripterAI
Discord ↗
Link Copied to Clipboard
×
"script an attacking npc with the roblox walk animations and tell me where the script goes"
-- server script (ServerScriptService) local npc = game.Workspace.NPC local humanoid = npc.Humanoid local animation = Instance.new("Animation") animation.AnimationId = "rbxassetid://507770453" -- Roblox walk animation ID local animationTrack = humanoid:LoadAnimation(animation) local function attack(target) npc.HumanoidRootPart.CFrame = CFrame.new(npc.HumanoidRootPart.Position, target.Position) -- Face the target npc.Humanoid:MoveTo(target.Position) -- Move to target animationTrack:Play() -- Play walk animation -- Attack logic goes here end local function findClosestPlayer() local closestPlayer = nil local closestDistance = math.huge for _, player in ipairs(game.Players:GetPlayers()) do local character = player.Character if character then local distance = (npc.HumanoidRootPart.Position - character.HumanoidRootPart.Position).Magnitude if distance < closestDistance then closestPlayer = character closestDistance = distance end end end return closestPlayer end while true do local target = findClosestPlayer() if target then attack(target) end wait(1) end -- Place this script inside a ServerScriptService folder. The NPC model should be in the Workspace with a Humanoid and HumanoidRootPart.