Sword script won't play attack animation

I have this script inside of a sword in the StarterGear, The player RigType is set to R15
The animation is made for R15
The Animation was uploaded.

Script:

Tool = script.Parent
Handle = Tool:WaitForChild("Handle")

local BaseUrl = "rbxassetid://"

Players = game:GetService("Players")
Debris = game:GetService("Debris")
RunService = game:GetService("RunService")

DamageValues = {
	BaseDamage = 6,
	SlashDamage = 20,
}

--For R15 avatars
Animation = 566593606

Damage = DamageValues.BaseDamage

Sounds = {
	Slash = Handle:WaitForChild("Slash"),
	Hit = Handle:WaitForChild("Hit"),
	Unsheath = Handle:WaitForChild("Unsheath")
}

ToolEquipped = false


Tool.Enabled = true

function TagHumanoid(humanoid, player)
	local Creator_Tag = Instance.new("ObjectValue")
	Creator_Tag.Name = "creator"
	Creator_Tag.Value = player
	Debris:AddItem(Creator_Tag, 2)
	Creator_Tag.Parent = humanoid
end

function UntagHumanoid(humanoid)
	for i, v in pairs(humanoid:GetChildren()) do
		if v:IsA("ObjectValue") and v.Name == "creator" then
			v:Destroy()
		end
	end
end

function Blow(Hit)
	if not Hit or not Hit.Parent or not CheckIfAlive() or not ToolEquipped then
		return
	end
	local character = Hit.Parent
	if character == Character then
		return
	end
	local humanoid = character:FindFirstChildOfClass("Humanoid")
	if not humanoid or humanoid.Health == 0 then
		return
	end
	local player = Players:GetPlayerFromCharacter(character)
	if player and (player == Player) then
		return
	end
	UntagHumanoid(humanoid)
	TagHumanoid(humanoid, Player)
	humanoid:TakeDamage(Damage)	
end


function Attack()
	Damage = DamageValues.SlashDamage
	Sounds.Slash:Play()
	Sounds.Hit:Play()
	if Humanoid then
		local Track = Humanoid.Animator:LoadAnimation(script.attack)
		Track:Play()
	end	
end

Tool.Enabled = true
LastAttack = 0

function Activated()
	if not Tool.Enabled or not ToolEquipped or not CheckIfAlive() then
		return
	end
	Tool.Enabled = false
	Attack()
	--wait(0.5)
	Damage = DamageValues.BaseDamage
	local SlashAnim = (script.attack)

	Tool.Enabled = true
end

function CheckIfAlive()
	return (((Player and Player.Parent and Character and Character.Parent and Humanoid and Humanoid.Parent and Humanoid.Health > 0 and Torso and Torso.Parent) and true) or false)
end

function Equipped()
	Character = Tool.Parent
	Player = Players:GetPlayerFromCharacter(Character)
	Humanoid = Character:FindFirstChildOfClass("Humanoid")
	Torso = Character:FindFirstChild("Torso") or Character:FindFirstChild("HumanoidRootPart")
	if not CheckIfAlive() then
		return
	end
	ToolEquipped = true
	Sounds.Unsheath:Play()
end

function Unequipped()
	ToolEquipped = false
end

Tool.Activated:Connect(Activated)
Tool.Equipped:Connect(Equipped)
Tool.Unequipped:Connect(Unequipped)

Connection = Handle.Touched:Connect(Blow)

This is the Roblox Classic Sword script, but with some modifications I might be missing something in the script, but I can’t seem to figure it out and I don’t get any errors in the workspace.

The sword plays the slash and hit sounds and deals damage it just doesn’t play the animation.

1 Like

This line is trying to load an animation that is inside the sword script, has the animation child of the script been updated to the new id?

If this is within a Sever script, then the issue is that animations can’t be loaded to clients’ rigs from the server. This is because clients have network ownership over their characters.

One solution would be to fire the client with the animation you wish to play, and handle the playing of said animation on the client that received the invocation.

So I made a local script inside of the same tool, the script activates when an event that is in the Replicated storage gets fired, my issue is the same. The animation won’t work.

Local Script:

local eve = game.ReplicatedStorage.Attack
print(1)
eve.OnClientEvent:Connect(function(plr)
	print(2)
	local track = script.Parent.Parent.Humanoid.Animator:LoadAnimation(script.attack)
print(3)
	track:Play()
	print(4)
end)

It prints 1 as soon as I join, when I click it prints: 2,3 and 4. That means it reaches the end of the script without playing the animation. Is there a way I could fix this?

Load the animation to the Humanoid and not the Animator. If that doesn’t work, make sure the animation is uploaded to the correct place holder.

Yeah I uploaded this game to my group, but the animation was uploaded to my account. That fixed it Thanks.