Tool weapon sometimes not damaging

Sometimes the tool damage works, sometimes it doesn’t. The cooldowns look correct. No clue why it’s doing this.

2 Likes

More information is needed. It could be an issue with the code, hitboxes, or something else.

Model is welded to a part named “Handle” that serves as the hitbox.

script

local rs = game:GetService("ReplicatedStorage")
local fire = rs.Fire
local parent = script.Parent
local Handle = parent:WaitForChild("Handle")
local Creator = parent:WaitForChild("Creator")

CanDmg = false
Can = true
Sdamage = 1
damage = 23
cd = 0.46
scd = 0.30



parent.Activated:Connect(function()
	function slash()
		print("hip")
		local creator = Creator.Value

		if Can == true then
			Can = false
			wait(.19)
			CanDmg = true
			wait(0.25)
			CanDmg = false
			wait(cd)
			Can = true

		end
	end
	slash()
end)
function on(t)
	local h = t.Parent:FindFirstChildOfClass("Humanoid")
	
	if h ~= nil and CanDmg == true then
		CanDmg = false
		local cre = Creator.Value
		h:TakeDamage(damage)
		Handle.Swing:Stop()
		Handle.Hit:Play()
		if h.Health>0 then
			if not h:FindFirstChild("creator") then
				local ov = Instance.new("ObjectValue",h)
				ov.Name = "creator"
				ov.Value = game.Players:WaitForChild(cre.Name)
			else
				local ovs = h:GetChildren()
				for i = 1,#ovs do
					if (ovs[i].Name == "creator") then
						ovs[i].Value = game.Players:WaitForChild(cre.Name) end
				end
			end
		end
	end
end


Handle.Touched:Connect(on)

Localscript

local rs = game:GetService("ReplicatedStorage")
local fire = rs.Fire
local ContextActionService = game:GetService("ContextActionService")
local parent = script.Parent
local Handle = parent:WaitForChild("Handle")
local Creator = parent:WaitForChild("Creator")
local Players = game:GetService("Players")

local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()

-- Ensure that the character's humanoid contains an "Animator" object
local Humanoid = character:WaitForChild("Humanoid")
EquipAnim = parent.Animations.Equip
IdleAnim = parent.Animations.Idle
Attack = parent.Animations.Attack
local Equip = Humanoid:WaitForChild("Animator"):LoadAnimation(EquipAnim)
local Idle = Humanoid:WaitForChild("Animator"):LoadAnimation(IdleAnim)
local Attack = Humanoid:WaitForChild("Animator"):LoadAnimation(Attack)
CanDmg = false
Can = true
cd = 0.44


parent.Unequipped:Connect(function()
	Unequip()
	Handle.UnEquip:Play()
	Attack:Stop()
	Idle:Stop()
end)
function Unequip()
	if Attack.IsPlaying  then
		Attack:Stop()
		wait(.1)
		Idle:Stop()
		if Idle.IsPlaying then
			Idle:Stop()
		end
	end
end

parent.Equipped:Connect(function()
	
	Handle.Equip:Play()
	if Creator.Value == nil then
		Creator.Value = parent.Parent end
	Equip:Play()
	wait()
	Idle:Play()
end)

parent.Activated:Connect(function()
	function slash()
		local creator = Creator.Value
		if Can == true then
			Humanoid.JumpPower = 0
			Idle:Stop()
			Can = false
			Attack:Play()
			wait(0.19)
			Handle.Swing:Play()
			CanDmg = true
			Humanoid.JumpPower = 60.999
			wait(.25)
			CanDmg = false
			Idle:Play()
			wait(cd)
			Can = true

		end
	end
	slash()
end)


function runFunction()
	Humanoid.WalkSpeed = 12
	wait(cd)
	Humanoid.WalkSpeed = 24
end