.Touched not firing for whatever reason

Hello, for some reason my system does not work. Preferably on the part where it checks if its been touched.

The Code:

local ServerScriptService = game:GetService("ServerScriptService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local ServerCombat = ServerScriptService:FindFirstChild("Server Combat")
local Remote = ReplicatedStorage.Remotes

-- hitbox script
game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(Character)
		local Script = ReplicatedStorage.Storage["Combat Hitbox"].Hitbox["Main Script"]:Clone()
		local Configs = ReplicatedStorage.Storage["Combat Hitbox"].Hitbox.Configuration:Clone()
		local Hitbox = Instance.new("Part", plr.Character["HumanoidRootPart"])
		local Weld = Instance.new("WeldConstraint", Hitbox)
		Hitbox:PivotTo(plr.Character["HumanoidRootPart"].CFrame)
		Weld.Part0 = Hitbox
		Weld.Part1 = plr.Character["HumanoidRootPart"]
		Hitbox.Massless = true
		Hitbox.CanCollide = false
		Hitbox.Transparency = 0.5
		Hitbox.Size = Vector3.new(5,6,2.8)
		Configs.Parent = Hitbox
		Configs.Owner.Value = plr.Name
	end)
end)

-- main script
Remote:WaitForChild("Hit").OnServerEvent:Connect(function(plr,input,Combo)
	if input == "M1" then
		if Combo == 1 then
			print(Combo)
			local Debounce = false
			Debounce = false
			local Hitbox = plr.Character.HumanoidRootPart.Part
			local Animation = ServerCombat.Anims["punch #1"]
			local AT = plr.Character.Humanoid:LoadAnimation(Animation)
			AT:Play()
			wait (0.1)
			Hitbox.Touched:Connect(function(target)
				if target.Parent.Name ~= plr.Name and Debounce == false then
						Debounce = true
						target.Humanoid.Health -= 5
				end
			end)
		elseif Combo == 2 then
			local Debounce = false
			Debounce = false
			local Hitbox = plr.Character.HumanoidRootPart.Part
				local Animation = ServerCombat.Anims["punch #2"]
				local AT = plr.Character.Humanoid:LoadAnimation(Animation)
				AT:Play()
				wait (0.1)
			Hitbox.Touched:Connect(function(target)
				if target.Parent.Name ~= plr.Name then
					if Debounce == false then
						Debounce = true
						target.Humanoid.Health -= 5
					end
				end
			end)
		elseif Combo == 3 then
			local Debounce = false
			Debounce = false
			local Hitbox = plr.Character.HumanoidRootPart.Part
			local Animation = ServerCombat.Anims["punch #1"]
			local AT = plr.Character.Humanoid:LoadAnimation(Animation)
			AT:Play()
			wait (0.1)
			Hitbox.Touched:Connect(function(target)
				print(target)
				if target.Parent.Name ~= plr.Name then
					if Debounce == false then
						Debounce = true
						target.Humanoid.Health -= 5
					end
				end
			end)
		end
	end
end)

4 Likes

Have you tried debugging like printing target.Parent.Name? Now nothing against your methods of hitboxes, but .Touched is very outdated and you should probably resort to more reliable and precise methods. You didn’t mention specifically what was going wrong, but a video would be helpful as well.

3 Likes

I have debugged and it just stops at .Touched. It works for other parts expect for this, also it just doesn’t fire.

3 Likes

You should probably use these to check for hitbox detection (GetPartBoundsInBox and GetPartBoundsInRadius)

They are more accurate and .Touched requires movement to fire which is probably why its not working

3 Likes

How would i use this? I’ve actaully never done this.

2 Likes

The documentation gives you the arguments that you need to pass into them

You need stuff like CFame and Size but you already have a hitbox part, so you can just use the CFrame or size of that

1 Like

This one (GetPartsInPart) gets all the parts inside of a part. It might be better for you since you have a hitbox part

1 Like

I’ve looked but how does this work? I seriously do not understand this and how would i put this into my script?

1 Like

I would search up a video on it if I were you, if you don’t understand it. Research and maybe someone else can explain it.

1 Like

you use

local parts = game.Workspace:GetPartsInPart(part)

and `parts’ will be a table that contains all the parts that the part was touching

1 Like

Try looking at raycast hitbox, it’s pretty simple and probably more performant than using a region query

1 Like

Ah so do i put it as like this

local hitbox = plr.Character["HumanoidRootPart"]:GetPartsInPart(part)
1 Like

use :GetPartsInPart on game.Workspace

and pass in the hitbox as the argument

it doesn’t return the hitbox but all the parts inside of the hitbox

local touchingParts = game.Workspace:GetPartsInPart(hitbox)

1 Like

Oh yeah, it doesnt even get the right part…

1 Like

Im trying out raycast hitbox v4, but it only works for tools. How would i use this into my script?

1 Like

Yeah, but it would lower the complexity and make it easier to change. Fair trade-off if you ask me but just a suggestion

1 Like

It’s fine, i will make it into a tool.

1 Like

It works without tools, you just specify the part that has the attachments or create points around a part

1 Like

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