So, i have an issue when my sword is swung and hits a part it breaks, i was not able to find a solution to this i tried to add an else statement but it still broke the whole thing. If anyone could help thanks.
Here is my code:
local player = game.Players.LocalPlayer
player.CharacterAdded:Connect(function()
local debounce = false
local hit = false
local tool = script.Parent
local Animations = tool:WaitForChild("Animations")
local min = tool.Min
local max = tool.Max
local animation1 = Animations:FindFirstChild("SwordIdle")
local animation2 = Animations:FindFirstChild("SwordSwing")
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local holdanim = humanoid:LoadAnimation(animation1)
local swinganim = humanoid:LoadAnimation(animation2)
local function Equipped()
holdanim:Play()
end
local function Unequipped()
holdanim:Stop()
end
local function Swing()
if not hit then
hit = true
holdanim:Stop()
swinganim:Play()
wait(1.3)
holdanim:Play()
hit = false
end
end
local function SwordCore(hit)
if not debounce then
debounce = true
wait(0.2)
local enemy = hit.Parent:FindFirstChild("Humanoid")
if enemy then
enemy.Health = enemy.Health - (math.random(min.Value, max.Value))
wait(1.3)
debounce = false
end
end
end
tool.Equipped:Connect(Equipped)
tool.Unequipped:Connect(Unequipped)
tool.Activated:Connect(Swing)
local player = game.Players.LocalPlayer
player.CharacterAdded:Connect(function()
local debounce = false
local hit = false
local tool = script.Parent
local Animations = tool:WaitForChild("Animations")
local min = tool.Min
local max = tool.Max
local animation1 = Animations:FindFirstChild("SwordIdle")
local animation2 = Animations:FindFirstChild("SwordSwing")
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local holdanim = humanoid:LoadAnimation(animation1)
local swinganim = humanoid:LoadAnimation(animation2)
local function Equipped()
holdanim:Play()
end
local function Unequipped()
holdanim:Stop()
end
local function Swing()
if not hit then
hit = true
holdanim:Stop()
swinganim:Play()
wait(1.3)
holdanim:Play()
hit = false
end
end
local function SwordCore(hit)
if not debounce then
debounce = true
wait(0.2)
local enemy = hit.Parent:FindFirstChild("Humanoid")
if enemy then
enemy.Health = enemy.Health - (math.random(min.Value, max.Value))
wait(1.3)
debounce = false
end
end
end
tool.Equipped:Connect(Equipped)
tool.Unequipped:Connect(Unequipped)
tool.Activated:Connect(Swing)
tool.Handle.Touched:Connect(SwordCore)
end)
end)

2 comments
Please, use proper indentation I can barely read the script.
What type of script is this?