So, i'm making a sword for my game because I don't wanna use some random free model, and i've come across a problem in which my sword does damage even when not activated. I then fixed that problem but now I have a problem where at first it doesn't do damage until it is swung and it hits a player or NPC, but then after that it goes back to how it was at first when it would hurt someone without even being swung. Now i'm trying to fix that. Here is my script. PS - The part where I attempted to fix is at the very bottom but it isn't working.
script.Parent.Equipped:Connect(function()
script.Parent.Activated:Connect(function()
script.Parent.Handle.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild('Humanoid') then
hit.Parent.Humanoid:TakeDamage(5)
end
end)
local animation = script.Parent.LeftSlash
local animation2 = script.Parent.SideSwipe
local pick = math.random(1,2)
if pick == 1 and script.Parent.Parent.Name ~= "Backpack" then
local play = script.Parent.Parent:WaitForChild("Humanoid"):LoadAnimation(animation)
play:Play()
script.Parent.Attack:Play()
elseif pick == 2 and script.Parent.Parent.Name ~= "Backpack" then
local play2 = script.Parent.Parent:WaitForChild("Humanoid"):LoadAnimation(animation2)
play2:Play()
script.Parent.Attack:Play()
end
local clone = script:Clone()
clone.Parent = script.Parent
script:Destroy()
end)
end)
