Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

LocalAnimation requires the Humanoid object?

Inside of a script for a skill, and animation is triggered, and it works until the player resets or dies. After they die, I get this message:

This is how it works normally.

Any ideas?

local Player = game.Players.LocalPlayer 
local mouse = Player:GetMouse() 
local lastUse = 0;
local char = Player.Character or Player.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")


local function onKeyDown(key) 
    local Key = key:lower()
    if key == "z" and Player.Levelss.Level.Value >= 15 and tick()-lastUse > 10 and Player.Levelss.RangedPunch.Value < 1  then
	    lastUse = tick();  
        local x = Instance.new("Part")
        x.BrickColor = BrickColor.new("White")
        x.Material = "Neon"
        x.CanCollide = false
        x.Transparency = 0.6
        x.Size = Vector3.new(10,10,10)
        x.TopSurface = "Smooth"
        x.BottomSurface = "Smooth"
        x.Shape = "Ball"
        x.Name = Player.Name
        local fd = script.fireDamage:clone()
        fd.Parent = x
        local a = Instance.new("Sound")
        a.SoundId = "http://www.roblox.com/asset/?id=260430117"
        a.Parent = x
        a.Volume = 2
        a:play()

 
       
        local animTrack = hum:LoadAnimation(script.Punch)
        animTrack:Play()
        wait(0.7)
        animTrack:Stop()



        Player.Levelss.XP.Value = Player.Levelss.XP.Value + 8


        local y = Instance.new("BodyVelocity")
        y.maxForce = Vector3.new(math.huge ,math.huge ,math.huge)
        y.velocity = Player.Character.Torso.CFrame.lookVector*95

        x.CFrame = Player.Character.Torso.CFrame*CFrame.new(0, 1 , -10)
        x.Parent = Workspace
        y.Parent = x    
        game.Debris:AddItem(x, 6)

        
    end
end


mouse.KeyDown:connect(onKeyDown)

4 comments

1

I've answered you multiple times informing you not to use KeyDown. Why are you still using it? :/

0

If KeyDown is the reason that it is happening, I will change it. But if it is not the reason for it, I will keep KeyDown. I'd like to keep this game as simple as possible for me at the moment.

0

First up, let me say, you're developing a lit game

0

Try having it print the humanoid's path using :GetFullName() and debug from there.

2 answers

✓ Accepted answer

I have experienced this as well; animations require an active humanoid. Assuming this is a player script which does not reset itself then you have to reset "hum" whenever a new character loads, and as a precaution, wait until there is a humanoid and it has a parent.

i.e.

player.CharacterAdded:connect(function(character)
        char = character
	hum = char:WaitForChild('Humanoid')
end)
if not hum.Parent then
	repeat wait(0.2) until hum.Parent
end
local animTrack = hum:LoadAnimation(script.Punch)
animTrack:Play()

p.s. like others said KeyDown is deprecated. If you like the string simplicity you can do this :)

game:GetService('UserInputService').InputBegan:connect(function(input,gpe)
	if not gpe then
		local key = string.lower(input.KeyCode.Name)
		onKeyDown(key)
	end
end)

Your solution sort of works, cabbler. But I still get this error message :l

4 comments

0

Show your code

0

I cant post another answer.. Will a gyazo work? (some parts are commented out so that it is not broken for my testers) https://gyazo.com/f0bd0639c29946a5dd6d4dd5ad9b54a2 II https://gyazo.com/0c00c702285b3adf54a4bd8f50895f9d

0

Try defining the characteradded function outside of the OnKeyDown function

0

Thanks a lot. That was a huge error on my part, sorry. Your solution worked. I love this site, people have saved my life so many times xD

This discussion is preserved as it was. New answers, comments, and votes are closed.