Hitbox rarely working

Hello! I am having a problem with my hitboxes. When the dummy is obviously touching the hitbox, the script doesn’t process it and no damage is done.
here is the local script:

wait(2)

local yevent = game.ReplicatedStorage.yujiEvent
local UIS = game:GetService("UserInputService")
local plr = game.Players.LocalPlayer
local p1 = script.p1
local p2 = script.p2
local p3 = script.p3
local isusingy = false



yevent.OnClientEvent:Connect(function()
	local char = plr.Character
	local p1l = char.Humanoid:LoadAnimation(p1)
	local p2l = char.Humanoid:LoadAnimation(p2)
	local p3l = char.Humanoid:LoadAnimation(p3)
	local stunned = char:GetAttribute("Stunned")
	local blocking = char:GetAttribute("Blocking")
	local canp2 = false
	local canp3 = false
	local isusingy = true
	UIS.InputBegan:Connect(function(input, gpc)
		if gpc then return end
		if input.UserInputType == Enum.UserInputType.MouseButton1 and canp2 == false and canp3 == false then
			if stunned == true or blocking == true then return end
			local hitbox = game.ReplicatedStorage.hitbox:Clone()
			hitbox.Parent = workspace
			hitbox.CFrame = char.HumanoidRootPart.CFrame + Vector3.new(0,0,-5) * char.HumanoidRootPart.CFrame.LookVector * -1
			p1l:Play()
			hitbox.TouchEnded:Connect(function(hit)
				if hit.Parent.Humanoid then
					if hit.Parent.Name ~= plr.Name then
						print(hit.Name)
						game.ReplicatedStorage.fightEvent:FireServer(isusingy, hit.Parent.Humanoid)
						hitbox:Destroy()
					end
				end
			end)
	
			canp2 = true
			wait(0.7)
			hitbox:Destroy()
			canp2 = false
		elseif input.UserInputType == Enum.UserInputType.MouseButton1 and canp2 == true and canp3 == false then
			local hitbox = game.ReplicatedStorage.hitbox:Clone()
			hitbox.Parent = workspace
			hitbox.CFrame = char.HumanoidRootPart.CFrame + Vector3.new(0,0,-5)* char.HumanoidRootPart.CFrame.LookVector * -1
			p2l:Play()
			hitbox.TouchEnded:Connect(function(hit)
				if hit.Parent.Humanoid then
					if hit.Parent.Name ~= plr.Name then
			
						game.ReplicatedStorage.fightEvent:FireServer(isusingy, hit.Parent.Humanoid)
						hitbox:Destroy()
					end
				end
			end)
			canp3 = true
			wait(0.7)
			hitbox:Destroy()
			canp3 = false
		elseif input.UserInputType == Enum.UserInputType.MouseButton1 and canp2 == false and canp3 == true then
			local hitbox = game.ReplicatedStorage.hitbox:Clone()
			hitbox.Parent = workspace
			hitbox.CFrame = char.HumanoidRootPart.CFrame + Vector3.new(0,0,-5)* char.HumanoidRootPart.CFrame.LookVector * -1
			p3l:Play()
			hitbox.TouchEnded:Connect(function(hit)
				if hit.Parent.Humanoid then
					if hit.Parent.Name ~= plr.Name then
						game.ReplicatedStorage.fightEvent:FireServer(isusingy, hit.Parent.Humanoid)
						hitbox:Destroy()
					end
				end
			end)
			wait(0.2)
			hitbox:Destroy()
		end
	end)
end)

Server Script:

local event = game.ReplicatedStorage.fightEvent

event.OnServerEvent:Connect(function(plr, isusingy, hum)
	if isusingy == true then
		hum:TakeDamage(5)
	end
end)

ijuhi9ouui9uyhguiuytguiouytguioikujyhtguioikuuytguioiuuyybump

The problem is that you’re using .Touched() (well technically you’re using .TouchEnded(), but they both suck). It’s not reliable and only useful for touch triggers. Instead, I would reccomend using :GetPartsInBox(), as it would provide the same box-like shape you’re looking for. I’ve written more information on the specifics in my post, The Basics of Combat Games: Hitboxes.

2 Likes

Just use HitboxService. It’s a more reliable service for hitboxes.

Thank you for the reply, but I figured it out afterward lol. thanks anyways tho. Thanks anyways.

Yeah i might just end up using a public module because my custom hitbox is giving me errors.