I'm trying to add multiple animations for a sword (Lunge, Slash, etc.) however I can't figure out how to tweak this script to do so.

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

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)	-- Fires The "PlayerHit" Event
			end																	
			if EnemyHit then													
				game.ReplicatedStorage.EnemyHit:FireServer(hit,EnemyHit,Tool)	Fires the "EnemyHit" Event
			end																	
			wait(0.7)															
			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(0.7)												
	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) 

1 comment

0

Please use code blocks.