This tool does not play an animation on click. Is there any problem to my script? There is no errors, so it could be something else.
local Sword = script.Parent
local Script = script
game.Players.PlayerAdded:Connect(function(player)
if player == game.Players.LocalPlayer then
local Character = player.Character
Sword.Activated:Connect(function()
local animation = Script:WaitForChild("SwordAnimation")
local track = Character.Humanoid:LoadAnimation(animation)
track:Play()
end)
end
end)
Is this on a server or local script? It should be on a server, and thus there are a few lines wrong/unnecessary:
local Sword = script.Parent
local Character = Sword.Parent
Sword.Activated:Connect(function()
local animation = script:WaitForChild("SwordAnimation")
local track = Character.Humanoid:LoadAnimation(animation)
track:Play()
end)
Try that and see if it helps (make sure to change to server script if you’re local)
There could be several reasons why the animation is not playing when you click the Sword tool. Here are a few things you could try:
Make sure that the “SwordAnimation” is a valid animation object. You can check this by looking for the animation object in the Explorer panel and making sure that it has the desired animation tracks.
Check if the “Character” object is properly defined. You may want to print the “Character” object to the Output panel to verify that it is not nil.
Make sure that the “Humanoid” object is properly defined. This is the object that you are trying to load the animation onto. If the “Humanoid” object is not defined, the “LoadAnimation” function will not work.
Check if the “Activated” event is being fired when you click the Sword tool. You can do this by printing a message to the Output panel in the “Activated” event handler.
Make sure that the “Humanoid” object is not already playing an animation. If the “Humanoid” object is already playing an animation, the “LoadAnimation” function will not work. You may need to stop any existing animations before trying to play the “SwordAnimation” object.