Im trying to inflict damage on a dummy with a punching script I made. In this script I used a part that appears and disappears each time the mouse is clicked, it inflicts damage but not all the time. This is the only hitbox method I know so please help me.
This is what it looks like: Punches
The grey part is my hit box and the dummy should take damage each time it touches it.
And this is a part of the script I'm using:
local debounce = false local Box = Instance.new("Part") local boxweld = Instance.new('Weld') boxweld.Name = "CWelds" boxweld.Part0 = Player.Character.Torso boxweld.Part1 = Box boxweld.Parent = Player.Character.Torso boxweld.C0 = CFrame.new(0, -1, -2)*CFrame.Angles(0, 0, 0) Box.Size = Vector3.new(4, 5, 4) Box.CanCollide = false Box.Anchored = false Box.Transparency = 0.5 Box.Name = "Box" Box.Parent = Player.Character Box.Touched:connect(function(part) local h = part.Parent:FindFirstChild("Humanoid") if h and (not debounce) and (h.Parent ~= Player.Character) then debounce = true h:TakeDamage(math.random(10, 14)) Box:Destroy() end end)
This isnt all of the script however it is where the problem is, if you need the whole script please tell me.
Raycasting
Have you considered instead checking if the Player is facing the target and if they can hit the target?
A lot of games out there use this method instead of checking the mesh because putting a hitbox on the weapon and checking for an intersection can be inconvenient in certain games where this checking is not reliable or necessary (More overhead than raycasting, provided their masking is right).
Send a ray from the torso, in the direction of the torso, for about 2.5 studs, check if it hits a character and then damage the character it hit. Make sure you set the mask to ignore the Player's character.