Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to make an RPG npc loads an animation when attacking? [closed]

Asked by 7 years ago

Please include the code which you are trying to use, so the community will be better-equipped to help you with your problem.

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.

0
Can you include your script in a code block. User#5423 17 — 7y

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?

1 answer

Log in to vote
0
Answered by 7 years ago

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

Ad