Hello everyone!, I am here to present you with a customizable sword script I made. You can customize the sounds, animations, attack damage, and speed. If you have suggestions, please message them below!
The script:
local damage = 10
local waitTime = 0.1
local swingAnimID = "13761775939"
local swingSoundID = "1306070008"
local equipAnimID = ""
local equipSoundID = "536068772"
local hitSoundID = "2648568095"
-- Customization Ends!
local sword = script.Parent
local hurtParts = sword:GetDescendants()
local canDamage = true
local isSwinging = false
local attackAnim = Instance.new("Animation", sword:FindFirstChildWhichIsA("Part"))
attackAnim.AnimationId = "rbxassetid://".. swingAnimID
local equipAnim = Instance.new("Animation", sword:FindFirstChildWhichIsA("Part"))
equipAnim.AnimationId = "rbxassetid://".. equipAnimID
local swingSound = Instance.new("Sound", sword:FindFirstChildWhichIsA("Part"))
swingSound.SoundId = "rbxassetid://".. swingSoundID
local equipSound = Instance.new("Sound", sword:FindFirstChildWhichIsA("Part"))
equipSound.SoundId = "rbxassetid://".. equipSoundID
local hitSound = Instance.new("Sound", sword:FindFirstChildWhichIsA("Part"))
hitSound.SoundId = "rbxassetid://".. hitSoundID
local attackAnimTrack
local equipAnimTrack
if type(hurtParts) ~= "table" then
sword:FindFirstChildWhichIsA("Part").Touched:Connect(function(hit)
if canDamage and isSwinging and hit and hit.Parent:FindFirstChild("Humanoid") then
canDamage = false
hitSound:Play()
hit.Parent["Humanoid"]:TakeDamage(damage)
task.wait(waitTime)
canDamage = true
end
end)
else
for _, part in pairs(hurtParts) do
if part:IsA("Part") then
part.Touched:Connect(function(hit)
if canDamage and isSwinging and hit and hit.Parent:FindFirstChild("Humanoid") then
canDamage = false
hitSound:Play()
hit.Parent["Humanoid"]:TakeDamage(damage)
task.wait(waitTime)
canDamage = true
end
end)
end
end
end
script.Parent.Equipped:Connect(function()
if not attackAnimTrack then
attackAnimTrack = script.Parent.Parent.Humanoid.Animator:LoadAnimation(attackAnim)
attackAnimTrack.Priority = Enum.AnimationPriority.Action
end
if not equipAnimTrack then
equipAnimTrack = script.Parent.Parent.Humanoid.Animator:LoadAnimation(equipAnim)
equipAnimTrack.Priority = Enum.AnimationPriority.Action
end
equipAnimTrack:Play()
equipSound:Play()
end)
script.Parent.Activated:Connect(function()
if not isSwinging and canDamage then
attackAnimTrack:Play()
swingSound:Play()
isSwinging = true
task.wait(attackAnimTrack.Length)
isSwinging = false
end
end)
for _, part in pairs(sword:GetDescendants()) do
if part:IsA("Part") then
part.CanTouch = true
part.CanCollide = false
end
end