I would really like you to rate my code. I’m also confused by the fact that I placed it in the Tool, can exploiters take advantage of this?
local swordTool = script.Parent
local swordPart = script.Parent.Handle
local attack1Animation = game.ServerStorage.Animations.Attack1Animation
local attack2Animation = game.ServerStorage.Animations.Attack2Animation
local equipmentSound = swordPart.Unsheath
local swingSound = swordPart.SwordSlash
local hitSound= swordPart.SwordLunge
local animation
local isActivated = false
local cooldown = false
swordPart.Touched:Connect(function(part)
if not isActivated or cooldown then return end
cooldown = true
local touchedPlayer = game.Players:GetPlayerFromCharacter(part.Parent)
if touchedPlayer then
touchedPlayer.Character.Humanoid:TakeDamage(swordTool.Damage.Value)
hitSound:Play()
local player = game.Players:GetPlayerFromCharacter(swordTool.Parent)
if touchedPlayer.Character.Humanoid.Health <= 0 then
player.leaderstats.Coins.Value += 10
print(player.Name.."was awarded 10 coins for kill")
print(player.Name.." killed "..touchedPlayer.Name)
end
end
task.wait(1)
cooldown = false
end)
swordTool.Equipped:Connect(function()
equipmentSound:Play()
end)
swordTool.Activated:Connect(function()
if isActivated then return end
isActivated = true
local animator = swordTool.Parent.Humanoid.Animator
if math.random() >= 0.5 then
animation = animator:LoadAnimation(attack1Animation)
else
animation = animator:LoadAnimation(attack2Animation)
end
animation:Play()
swingSound:Play()
task.wait(1)
isActivated = false
end)