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

LoadAnimation requires the Humanoid Object(Player1.Humanoid) to be a descendant of the game object?

local tool = script.Parent
local player = game.Players.LocalPlayer
local character = game.Players.LocalPlayer.Character or player.CharacterAdded:Wait()
local animation
local anim = script.Parent:WaitForChild("Animation"):Clone()
tool.Equipped:Connect(function()
	animation =character:WaitForChild("Humanoid"):LoadAnimation(anime)
	character = character or tool.Parent or player.Character or player.CharacterAdded:Wait()

   	 if not animation then
        animation = character.Humanoid:LoadAnimation(animation)
    end
end)
script.Parent.Unequipped:Connect(function()
	animation:Stop()
end)

I made a team change script that resets the character, then the animation of the tool is completely broken? how do I fix it?

When I reset this error shows up.

3 answers

animation =character:WaitForChild("Humanoid"):LoadAnimation(anime)

typo :)

edit:

local tool = script.Parent
local player = game.Players.LocalPlayer
local character = game.Players.LocalPlayer.Character or player.CharacterAdded:Wait()
local anim = script.Parent:WaitForChild("Animation") --No need to clone it
tool.Equipped:Connect(function()
    animation = character:WaitForChild("Humanoid"):LoadAnimation(anim)
    if not animation then
        animation = character.Humanoid:LoadAnimation(animation)
    end
	animation:Play()
end)
script.Parent.Unequipped:Connect(function()
    animation:Stop()
end)


4 comments

0

I have tried it before, it did not change anything.

0

'anime' is more than likely your problem here, since you didn't define it?

0

Changed that, still does not work

0

I fixed it myself, thanks for answering :D

local animation
script.Parent.Equipped:Connect(function()
    animation = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.Animation)
    animation:Play()
end)

script.Parent.Unequipped:Connect(function()
        animation:Stop()
end)
--Script that does work

I have fixed that. I found another script of animation that I have made a while ago that does work, I don't know what the error is but at least it works now.

I had this problem too...

Check if there is any other instance in your game that has your name

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