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

Animation doesn't work? LoadAnimation requires the Humanoid object?

I made a script where you press the key Q a part is created around the player. For some reason when I made the animation it doesn't work?

plr = game.Players.LocalPlayer
local char = plr.Character
--//Animation
local shield = Instance.new('Animation')
shield.AnimationId = 'http://www.roblox.com/asset/?id=959285490'
local shieldloader = plr.Character.Humanoid:LoadAnimation(shield)
--//
mouse = plr:GetMouse()
debounce = false


function onKeyPress(shield,userInputState,inputObject)
	if userInputState == Enum.UserInputState.Begin then
		wait()
		if not debounce then
			debounce = true
			plr.Character.Humanoid.WalkSpeed = 0
			plr.Character.Humanoid.JumpPower = 0
		s = Instance.new('Part')
		s.Anchored = true
		s.CanCollide = false
		s.Size = Vector3.new(25,25,25)
		s.Transparency = 0.7
		s.BrickColor = BrickColor.new('Cyan')
		s.CFrame = plr.Character.HumanoidRootPart.CFrame * CFrame.new(0,0,0)
		s.Parent = workspace
		shieldloader:Play()
		end
	elseif
		userInputState == Enum.UserInputState.End then
		plr.Character.Humanoid.WalkSpeed = 16
		plr.Character.Humanoid.JumpPower = 50
		s:Destroy()
		wait()
	end
	wait(10)
	debounce = false
end

game.ContextActionService:BindAction('keyPress',onKeyPress,false,Enum.KeyCode.Q)

Error: LoadAnimation requires the Humanoid object (luicasas.Humanoid) to be a descendant of the game object

1 answer

It is because the animation's parent is Workspace, it needs to be in the player humanoid I believe.

plr = game.Players.LocalPlayer
local char = plr.Character
--//Animation
local shield = Instance.new('Animation',char.Humanoid)
shield.AnimationId = 'http://www.roblox.com/asset/?id=959285490'
local shieldloader = plr.Character.Humanoid:LoadAnimation(shield)
--//
mouse = plr:GetMouse()
debounce = false


function onKeyPress(shield,userInputState,inputObject)
    if userInputState == Enum.UserInputState.Begin then
        wait()
        if not debounce then
            debounce = true
            plr.Character.Humanoid.WalkSpeed = 0
            plr.Character.Humanoid.JumpPower = 0
        s = Instance.new('Part')
        s.Anchored = true
        s.CanCollide = false
        s.Size = Vector3.new(25,25,25)
        s.Transparency = 0.7
        s.BrickColor = BrickColor.new('Cyan')
        s.CFrame = plr.Character.HumanoidRootPart.CFrame * CFrame.new(0,0,0)
        s.Parent = workspace
        shieldloader:Play()
        end
    elseif
        userInputState == Enum.UserInputState.End then
        plr.Character.Humanoid.WalkSpeed = 16
        plr.Character.Humanoid.JumpPower = 50
        s:Destroy()
        wait()
    end
    wait(10)
    debounce = false
end

game.ContextActionService:BindAction('keyPress',onKeyPress,false,Enum.KeyCode.Q)

I set the parent of the animation to the player humanoid.

1 comment

0

Didn't work, same error. Thanks though.

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