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

Why is my script not playing an animation?, im new to lua, and the output doesnt show any problem

local tool = script.Parent local anim = tool:WaitForChild("animation") local player = game:GetService("Players").LocalPlayer local char = player.CharacterAdded:Wait() local humanoid = char:WaitForChild("Humanoid") local loadanim = humanoid:LoadAnimation(anim)

tool.Activated:Connect(function() loadanim:Play() end)

I already have the animation on the tool with the id

3 answers

First of all, for future questions, can you format your script. that way its easier for people to answer

Second your problem is your waiting for CharacterAdded to run again, which if the player has the tool already, it will run right away, so changing local char = player.CharacterAdded:Wait() to local char = player.Character should be your fix.

Alongside this. Humanoid:LoadAnimation() is no longer as in use, you should instead use Humanoid.Animator:LoadAnimation() as its what is recommended.

1 comment

0

Oh my bad, how do i format the script? And the script works with only animations that are not the hand of the tool, by this I mean that when it is another hand that isnt the one holding the tool it works if it is another it doesnt work.

wait()
--// Services:
local players = game:GetService("Players")
--// Variables:
local animation = script:WaitForChild(Animation Name)
local tool = script.Parent
--// Character:
local player = players.LocalPlayer
local character = player.Character
local humanoid = character:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local loadedAnimation = animator:LoadAnimation(animation)
--// Events:
tool.Activated:Connect(function()
	loadedAnimation:Play()
end)

This should help

1 comment

0

Still the same problem, the hand holding the tool doesnt play animations https://prnt.sc/F-ls0rRocSn7 https://prnt.sc/KBPcCMkPEr4H

Oh nvm i found the answer. The answer was the priority

wait()
local players = game:GetService("Players")
local animation = script:WaitForChild("Animation")
local tool = script.Parent
local player = players.LocalPlayer
local character = player.Character
local humanoid = character:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local loadedAnimation = animator:LoadAnimation(animation)
loadedAnimation.Priority = Enum.AnimationPriority.Action

tool.Activated:Connect(function()
	loadedAnimation:Play()
end)

I added the priority and it works. Thank u both.

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