local tool = script.Parent
local canDamage = false
local canSwing = true

local function onTouch(otherPart)

	local humanoid = otherPart.Parent:FindFirstChild("Humanoid")

	if not humanoid then 
		return 
	end

	if humanoid.Parent ~= tool.Parent and canDamage then 
		humanoid:TakeDamage(35)
	else
		return
	end

	canDamage = false
end

local function slash()
	if canSwing then
		canSwing = false
		local animation = game.Players.LocalPlayer.Character.Humanoid:LoadAnmimation{script.Parent.Attack}
		animation:Play()
		canDamage = true
		wait(1) --cooldown time
		canSwing = true
	end
end

tool.Activated:Connect(slash)
tool.Handle.Touched:Connect(onTouch)

attack is in the same tool

2 comments

0

Is this a local script or a server script? If its local, you can't do game.Players

0

it is a local one