#can't find the humanoid

37 messages · Page 1 of 1 (latest)

whole skiff
#

So I need to have the animation defined before the animation actually plays. When I try to define with script.Parent.Parent.Humanoid it returns with a error. Any ideas

--UTILLITY__
local tool = script.Parent
local canhit = false
local debounce = false
local humanoid = tool.Parent.Parent.Humanoid
--MODIFIERS--
local Damage = 10
local waittime = 7
local fling = 0
--ANIMATION--
local animloop = 1
local anim1 = script.Parent.anim1
local anim2 = script.Parent.anim2
local animation2 = humanoid:LoadAnimation(anim2)
local animation1 = humanoid:LoadAnimation(anim1)

script.Parent.Activated:Connect(function()
    if debounce == false then
        --animation loop

        if animloop == 1 then
            animloop = 2
            animation2:Play()
        else
            animloop = 1
            animation1:Play()
        end
        --Debounce
        canhit = true
        debounce = true

        wait(waittime)

        canhit = false
        debounce = false
    end

end)

tool.Handle.Touched:Connect(function(hit)
    if animation1 or animation2 then
        if canhit == true then
            local humanoid = hit.Parent:FindFirstChild("Humanoid")        
            if humanoid then
                local rootpart = humanoid.Parent.HumanoidRootPart
                local BodyVelocity = Instance.new("BodyVelocity", rootpart)
                --Damage
                humanoid.Health = humanoid.Health - Damage
                --Fling Script
                BodyVelocity.Velocity = Vector3.new(math.random(0, fling), math.random(0, fling), math.random(0, fling))
                rootpart.Velocity = Vector3.new(math.random(0, fling), math.random(0, fling), math.random(0, fling))    
            end
        end
    end
end)
short timber
#

wheres is the script located

untold storm
#

why is there a humanoid variable in --UTILITY__

whole skiff
whole skiff
tawdry pier
#

youre defining the humanoid right when the script is running, which means the tool isnt in the players backpack yet so it returns nil as the humanoid, try using the equipped event and defining humanoid from there

#
tool.Equipped:Connect(function()
    humanoid = tool.Parent.Parent:WaitForChild("Humanoid")
    animation1 = humanoid:LoadAnimation(anim1)
    animation2 = humanoid:LoadAnimation(anim2)
end)

@whole skiff

whole skiff
tawdry pier
#

wdym?

whole skiff
#

Can I use the humanoid variable out of the equip function

whole skiff
#
local anim1 = script.Parent.anim1
local anim2 = script.Parent.anim2

tool.Equipped:Connect(function()
    local huma = tool.Parent.Parent:WaitForChild("Humanoid")
    local animation1 = huma:LoadAnimation(anim1)
    local animation2 = huma:LoadAnimation(anim2)
end)

animation1:Play()
#

the animation 1 comes out as a error

tawdry pier
#

so put both anim1 and anim2 inside the equipped event

whole skiff
feral creekBOT
#

studio** You are now Level 2! **studio

whole skiff
#

To play them

#

here is the other function

#
local anim1 = script.Parent.anim1
local anim2 = script.Parent.anim2

tool.Equipped:Connect(function()
    local huma = tool.Parent.Parent:WaitForChild("Humanoid")
    local animation1 = huma:LoadAnimation(anim1)
    local animation2 = huma:LoadAnimation(anim2)
end)

animation1:Play()

tool.Activated:Connect(function()
    if debounce == false then
        --animation loop

        if animloop == 1 then
            animloop = 2
            animation2:Play()
        else
            animloop = 1
            animation1:Play()
        end
        --Debounce
        canhit = true
        debounce = true

        wait(waittime)

        canhit = false
        debounce = false
    end

end)
#

OH SHOOT

#

Never mind

#

I just realised somthing'

tawdry pier
#

i mean i guess u can define both animation1 and animation2 at a higher scope

short timber
#

just declare the variables out

tawdry pier
#

so like

local anim1 = script.Parent.anim1
local anim2 = script.Parent.anim2

local animation1
local animation2

tool.Equipped:Connect(function()
    local huma = tool.Parent.Parent:WaitForChild("Humanoid")
    animation1 = huma:LoadAnimation(anim1)
    animation2 = huma:LoadAnimation(anim2)
end)

-- u need to make sure the tool is equipped before calling this
-- or check if animation1 ~= nil.
if animation1 then
    animation1:Play()
end
short timber
#

no?

#

why

#

just declare it

#
local anim1 = script.Parent.anim1
local anim2 = script.Parent.anim2

local huma = tool.Parent.Parent:WaitForChild("Humanoid")
local animation1 = huma:LoadAnimation(anim1)
local animation2 = huma:LoadAnimation(anim2)

tool.Equipped:Connect(function()

    
end)

-- u need to make sure the tool is equipped before calling this
-- or check if animation1 ~= nil.
if animation1 then
    animation1:Play()
end
tawdry pier
#

???

short timber
#

yes?

tawdry pier
#

so youre playing the animation outside the equipped event?

short timber
#

just move it

#

between not mine u r the one who putted that there lol

tawdry pier
#

holy fuck im brainded

#

@whole skiff yea hes right i probably confused myself lol

whole skiff
#

yea