I'm trying to make my own sword and everything is working fine except that it isn't doing any damage
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
local tool = script.Parent
local idle = script:FindFirstChild("Idle")
local equipped= false
local debounce = false
local dmg = math.random(20,30)
tool.Equipped:Connect(function()
local idleanim = hum:LoadAnimation(idle)
idleanim:Play()
equipped = true
end)
tool.Activated:Connect(function()
local chance = math.random(1,2)
if chance == 1 and equipped == true and debounce == false then
debounce = true
local swordanim = hum:LoadAnimation(script.Sword1)
swordanim:Play()
local x = Instance.new("Part")
x.TopSurface = "Smooth"
x.BottomSurface = "Smooth"
x.Name = "Punch"
x.Shape = "Block"
x.CanCollide = false
x.Anchored = false
x.Transparency = 1
x.Parent = char
x.Size = tool.Handle.Blade.Size
x.CFrame = tool.Handle.Blade.CFrame
local w = Instance.new("Weld", x)
w.Part0 = x
w.Part1 = tool.Handle.Blade
x.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") == true and hit.Parent.Name ~= script.Parent.Parent.Parent.Name then
hit.Parent.Humanoid:TakeDamage(dmg)
end
end)
wait(.5)
debounce = false
elseif chance == 2 and equipped == true and debounce == false then
debounce = true
local swordanim = hum:LoadAnimation(script.Sword2)
swordanim:Play()
local x = Instance.new("Part")
x.TopSurface = "Smooth"
x.BottomSurface = "Smooth"
x.Name = "Punch"
x.Shape = "Block"
x.CanCollide = false
x.Anchored = false
x.Transparency = 1
x.Parent = char
x.Size = tool.Handle.Blade.Size
x.CFrame = tool.Handle.Blade.CFrame
local w = Instance.new("Weld", x)
w.Part0 = x
w.Part1 = tool.Handle.Blade
x.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") == true and hit.Parent.Name ~= script.Parent.Parent.Parent.Name then
hit.Parent.Humanoid:TakeDamage(dmg)
end
end)
wait(.5)
debounce = false
end
end)
tool.Unequipped:Connect(function()
equipped = false
for _, anim in pairs(hum:GetPlayingAnimationTracks()) do
anim:stop()
end
end)

1 comment
And all of my sword parts are inside the handle part