How would you make this animation play on click?

This animation does not play when clicked, but “I was clicked” is still in the output.

local LocalPlayer = game.Players.LocalPlayer
local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local Sword = script.Parent

Sword.Activated:Connect(function()
	print("I was clicked")
	local Animation = Sword.SwordAnimation
	local AnimationTrack = Humanoid:LoadAnimation(Animation)
	AnimationTrack:Play()
end)


Try loading the Animation before the Click

Im assuming the sword is a tool so i could set the character to the sword parent

also use math.huge probably because of loading issues

local Sword = script.Parent
local Character = Sword.Parent
local Humanoid = Character:WaitForChild("Humanoid", math.huge)
local Animation = Sword:WaitForChild("SwordAnimation", math.huge)
local AnimationTrack = Humanoid:LoadAnimation(Animation)

Sword.Activated:Connect(function()
	print("I was clicked")

	AnimationTrack:Play()
end)

There is no output when I click with the tool.

Does the animation track exists? Open the explorer bar and search it in your character.

Would the track be the actual Animation Name in the Players Tab?
This is all I can really find.

image

Instance the animation, example

Player = game.Players.LocalPlayer
local TorsoRot = Instance.new("Animation")
TorsoRot.AnimationId = "rbxassetid://11641202131"
local PlayTorsoRot = Player.Character.Humanoid:LoadAnimation(TorsoRot)

Instead of

local Humanoid = Character:WaitForChild("Humanoid", math.huge)
local Animation = Sword:WaitForChild("SwordAnimation", math.huge)
local AnimationTrack = Humanoid:LoadAnimation(Animation)

(2nd reply sorry had to)

Or 2nd alternative

-- Variables
local Player = game.Players.LocalPlayer
local Sword = script.Parent
local Character = Sword.Parent

-- Manually Create The Animation
local SwordAnim = Instance.new("Animation")
SwordAnim .AnimationId = "rbxassetid://youridhere"
local PlaySword = Player.Character.Humanoid:LoadAnimation(SwordAnim)

--  OnActivated
local function onActivated()
	print("I was clicked")

	local AnimationTrack = Humanoid:LoadAnimation(Animation)
	PlaySword:Play()
end

Sword.Activated:Connect(onActivated)

Ok, I edited your code a bit to fix some errors, and it actually does play the animation, however the holding animation for every item seems to overwrite it. Would there be a way to overwrite that animation?

Elaborate a little bit please

Re-read it, sorry… you can :Stop the holding animation in the script & re-play it when the PlaySword animation stopped

<30chh>

local LocalPlayer = game.Players.LocalPlayer
local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild(“Humanoid”)
local Sword = script.Parent

Sword.Activated:Connect(function()
print(“I was clicked”)
local Animation = Sword.SwordAnimation
local AnimationTrack = Humanoid:LoadAnimation(Animation)
AnimationTrack:Play()
end)

]]

local LocalPlayer = game:GetService(“Players”).LocalPlayer
local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild(“Humanoid”)
local Sword = script.Parent

local function OnClicked()
print(“I was clicked”)
local Animation = Sword.SwordAnimation
local AnimationTrack = Humanoid:LoadAnimation(Animation)
AnimationTrack:Play()
end

Sword.Activated:Connect(OnClicked)

1 Like