part.Touched not registering properly

I have 2 melee weapons that use part.Touched to do damage. It does work but it doesn’t work when the weapon is already touching the player’s hitbox before I press attack. Is there a way/alternative to get around this issue? I’ve been searching on forums but couldn’t find one.

The script for the weapon is;

local tool = script.Parent
local handle = tool.Handle
local debounce = false
local activated = false
local debounce2 = false

local anim2 = handle.Animation2

tool.Activated:Connect(function()
	if debounce then return end
	debounce = true
	activated = true
	handle["Cylinder.001"].saber_swing1:Play()
	handle["Cylinder.001"].Trail.Enabled = true
	local animation = tool.Parent:FindFirstChild("Humanoid"):LoadAnimation(anim2)
	animation:Play()
	task.wait(0.4)
	handle["Cylinder.001"].Trail.Enabled = false
	task.wait(0.3)
	activated = false
	debounce = false
end)

tool.Handle["Cylinder.001"].Touched:Connect(function(hit)
	if activated and not debounce2 then
		debounce2 = true
		if hit.Parent:FindFirstChild("Humanoid") and hit.Name == "Hitbox" and hit:GetAttribute("IsAHitbox") then
			hit.Parent:FindFirstChild("Humanoid"):TakeDamage(30)
			tool.Handle["Cylinder.001"]["Beat Saber Hit Sound (Short left)"]:Play()
		end
		task.wait(0.69)
		debounce2 = false
	end
end)

This script is for the saber, the other melee has the same script with different directories and different damage values.

The Touched event is very innacurate and buggy by itself. I recommend using different hitbox methods, such as the RotatedRegion3 Module (it may be considered “old”, but it’s still very useful) to create a hitbox with the shape of a square in front of the character or maybe with the exact size and position of the sword.

1 Like

I’ll take a look into that, thanks.

Oh wait, I already do have a hitbox though.

I’m not talking about player hitboxes, but damage hitboxes.

RotatedRegion3 is capable of making a box, circle, etc. (which is not a part) anywhere with any size and return objects inside that box.

you can also use raycast hitbox

1 Like

Ah okay but I think I’ll go with raycast hitbox.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.