Help me why doesnot this script work

this script works fine if I donot add candamage and slash . But i need those can anybody help why aint this script work if i add cooldown .

local tool = script.Parent
local Anim ={tool.Animation,tool.AnimationIdle}
local tool = script.Parent
local candamage = false
local slash = true
local function ontouch(otherpart)
local character = otherpart.Parent
local humanoid = character:FindFirstChild(“Humanoid”)

if not humanoid then return end 
if humanoid.Parent~=otherpart.Parent and candamage==true then 
	print("now we can damage")
	

	humanoid.Health=humanoid.Health-30
	candamage=false
	end

end

local track
tool.Equipped:Connect(function()
track = script.Parent.Parent.Humanoid:LoadAnimation(Anim[2])
track:Play()
end)

tool.Unequipped:Connect(function()
track:Stop()
end)
local function slash()
if slash==true then
print(“canslash”)
slash = false
local slash = script.Parent.Parent.Humanoid:LoadAnimation(Anim[1])
slash:Play()
candamage=true
wait(0.1)
slash=true
end
end
tool.Activated:Connect(function(slash)
tool.Blade.Touched:Connect(function(otherpart)
ontouch(otherpart)
end)
end)

1 Like

Hey, can you format your code using three back ticks (```) so it’s more legible? A more thorough explanation would also be helpful

1 Like

I dont understant . use back ticket ? . I m new

Try putting a slash() function in the activated function, remove the slash variable in the activated function, as it is not even used in the function, you should also rename the “slash” function to “slasher”, do the same to the slash() in the activated function

You also have a duplicate “tool” variable, so might wanna remove one of it since it’s unnecessary

1 Like

Not an easy-to-read one :slight_smile:

slash() is a function
slash is a local variable outside of the slash() function
slash is a local variable inside the slash() function

Probably this can lead some bug, you could try to rename them first and then you will see where you are.

1 Like

Sorry for that . And thankyou very much it worked now i was so stupid to not realize that .

1 Like

And thankyou all for your effort