Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

sword damage not working for some reason??

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

0

And all of my sword parts are inside the handle part

1 answer

Instead of making the part through the script, just make that part inside the tool. Then connect your touched events to that part you made so you don’t go through the struggle of making welds using a script.

Hope this helped!

This discussion is preserved as it was. New answers, comments, and votes are closed.