I'm making a simple sword for my game but the animation wont play.

  • script
local debounce = false
local Tool     = script.Parent
local Handle   = Tool:WaitForChild("Handle")
ValueCooldown  = false

function SwordCore(hit)
	local Enemys = hit.Parent:FindFirstChildOfClass("Humanoid")
	if script.CanDamage.Value and Enemys then
		local EnemyHit = hit.Parent:FindFirstChild("Enemy")
		local PlayerHit = hit.Parent:FindFirstChild("Humanoid")
		local Character = Tool.Parent
		local Player = game.Players:GetPlayerFromCharacter(Character)
		if (not Player) then return end
		local Humanoid = Character:FindFirstChild("Humanoid")
		if (not Humanoid) then return end
		if Enemys ~= Humanoid and (not debounce) then
			if Enemys.Health <= 0 then return end
			debounce = true
			if PlayerHit then
				game.ReplicatedStorage.PlayerHit:FireServer(hit,PlayerHit,Tool)
			end	
			if EnemyHit then
				game.ReplicatedStorage.EnemyHit:FireServer(hit,EnemyHit,Tool)
			end
			wait(1)
			debounce = false
		end
	end
end

function onActivated()
	if (not Tool.Enabled) then return end
	Tool.Enabled = false
	local Character = Tool.Parent
	local Humanoid = Character:FindFirstChild("Humanoid")
	local Anim = Humanoid:LoadAnimation(Tool.Slash)
	local SlashSound = Handle:WaitForChild("SlashSound")
	if (Humanoid == nil) then return end
	SlashSound:Play()
	Anim:Play()
	Tool.Unequipped:Connect(function()
		Anim:Stop()
	end)
	wait(1)
	Tool.Enabled = true
end

function onEquipped()
	if (not Tool) then return end
	if (not Handle) then return end
	if Handle.UnsheathSound.IsPlaying == false then
		Handle.UnsheathSound:Play()
	end
end	

function onUnEquipped()
	if (not Tool) then return end
	if (not Handle) then return end
	Handle.UnsheathSound:Stop()
end	

function checkValue()
	if ValueCooldown           == false then
		ValueCooldown          = true
		script.CanDamage.Value = true
		wait(1)
		script.CanDamage.Value = false
		ValueCooldown          = false
	end
end

Tool.Activated:Connect(onActivated)
Tool.Activated:Connect(checkValue)
Tool.Equipped:Connect(onEquipped)
Tool.Unequipped:Connect(onUnEquipped)

Handle.Touched:Connect(SwordCore)

5 comments

0

Are the animations in Handle?

0

Do you own the animation ? Is the animation ID correct? Does you tool have RequireHandle checked?

0

Do you own the animation ? Is the animation ID correct? Does you tool have RequireHandle checked?

0

Yes i do own the animation i made it. And the animation isnt in the handle.

0

And yes it does have RequireHandle checked.