i wanted to make an npc that loads an animation when attacking but nothing worked, and i need it in one script because i have to make a delay for the attack, thank you.
Heres the code i am using that doesn't work of course
local larm = script.Parent:FindFirstChild("Left Arm") local rarm = script.Parent:FindFirstChild("Right Arm") function findNearestTorso(pos) local list = game.Workspace:children() local HumanoidRootPart = nil local dist = 100 local temp = nil local human = nil local temp2 = nil for x = 1, #list do temp2 = list[x] if (temp2.className == "Model") and (temp2 ~= script.Parent) then temp = temp2:findFirstChild("HumanoidRootPart") human = temp2:findFirstChild("Humanoid") if (temp ~= nil) and (human ~= nil) and (human.Health > 0) then if (temp.Position - pos).magnitude < dist then HumanoidRootPart = temp dist = (temp.Position - pos).magnitude end end end end return HumanoidRootPart end function Hit(hit) local human = hit.Parent:FindFirstChild("Humanoid") if human ~= nil then local animation = Instance.new("Animation") animation.AnimationId = "http://www.roblox.com/Asset?ID=714140890" -- your id here local animController = Instance.new("AnimationController") local animTrack = animController:LoadAnimation(animation) animTrack:Play() human.Health =- 30 wait(4.5) end end larm.Touched:connect(Hit) rarm.Touched:connect(Hit) while true do wait(0.1) local target = findNearestTorso(script.Parent.Torso.Position) if target ~= nil then script.Parent.Zombie:MoveTo(target.Position, target) end end
Closed as Not Constructive by abnotaddable, Redbullusa, and shayner32
This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.
Why was this question closed?