Why is my touched event not firing?

Please don’t click off of this once you see the script is kinda big, I swear it’s not that complicated.

		
		
		
		local validPlayers = game.Players:GetPlayers()
		
		local connection --setting up connection variable to be used later
		
		local function finalSlashHitDetectionFunction(hit)
			if hit.Parent:FindFirstChild("Humanoid") and hit.Parent.Name ~= "clone" then
				--deal damage to hit
				hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - finalSlashDamage
				
				--removal from validPlayers list
				if game.Players:GetPlayerFromCharacter(hit.Parent) then --if it is in fact a player
					--first use table.find to get their index
					local index = table.find(validPlayers, game.Players:GetPlayerFromCharacter(hit.Parent))
					
					--remove them from the list
					table.remove(validPlayers, index)
					
				end
			end
		end
		
		finalSlashAnim:GetMarkerReachedSignal("superSlashEffectTrigger"):Connect(function()
			--disable player collisions, add trails and/or fire to every part of their body
			--connect damage function, make them zoom forward, sfx
			
			--disable player collisions
			for i, part in pairs(plr.Character:GetDescendants()) do
				if part.ClassName == "Part" then
					physicsServ:SetPartCollisionGroup(part, "finalSlashUser")
				end
			end
			
			
			--adding hitbox to player
			local boxOrientation, boxSize = plr.Character:GetBoundingBox()
			local hitBox = Instance.new("Part")
			hitBox.CanCollide = false
			hitBox.Transparency = 1
			hitBox.Massless = true
			hitBox.Size = boxSize
			hitBox.Name = "finalSlashHitBox"
			hitBox.Parent = plr.Character

			--welding to humanoidRootPart
			local hitBoxWeld = Instance.new("ManualWeld")
			hitBoxWeld.Part0 = plr.Character.HumanoidRootPart
			hitBoxWeld.Part1 = hitBox
			hitBoxWeld.Parent = hitBoxWeld.Part0
			
			
			
			--connect damage function
			connection = plr.Character.finalSlashHitBox.Touched:Connect(finalSlashHitDetectionFunction)
			
		
		
		finalSlashAnim:GetMarkerReachedSignal("superSlashStop"):Connect(function()
			--enable player collisions, delete all trails/fire, disconnect damage function
			--unfreeze player, enable inventory, trigger cooldown stuff and all that
			
			
			--enable player collisions
			for i, part in pairs(plr.Character:GetDescendants()) do
				if part.ClassName == "Part" then
					physicsServ:SetPartCollisionGroup(part, "players")
				end
			end
			
			
			
			
			
			--disconnect damage function
			connection:Disconnect()

			
			
			--wait until the end of the animation, because there needs to be a dramatic pause
			finalSlashAnim.Stopped:Wait()
			
			--delete hitbox
			if plr.Character:FindFirstChild("finalSlashHitBox") then
				plr.Character.finalSlashHitBox:Destroy()
			end

These are all in a server script, under a remote event.
Everything about this script works fine - except the touched event.
It rarely ever works, and I haven’t the slightest idea why.
I added a print(“AAAAAAA”) that’s immediately after it’s fired, and it never prints anything. Also, I made it so the hitbox is literally just welded to me and it prints “AAAAAAA” like once in a blue moon.
Why is this? I’m getting extremely annoyed

There could be a lot of things that could be going wrong here. I skimmed the code, but make sure your touch event is getting connected correctly. In addition to that, the .Touched event is not reliable, but it sounds like it’s generally not working at all, so I don’t think that’s it.

Additionally, since your scripts are entirely server sided and the player’s actions are happening on the client, there could be a mismatch going on due to latency. You may need to move the hit detection to the client and then use distance to confirm the hit on the server.

Also, your setup may not be secure because the client will always have the network ownership of their own character and can spoof the .Touched event. (Maybe there’s a way you can change the hitbox’s network ownership, but again latency would be a big issue in practice.)

Well yeah, but this is generally the same thing as I’ve done for multiple other scripts, and it’s worked fine for those. In fact, those scripts were actually all in the same script, just separate remote events.

Also, I’ve multiplied the hitbox by 3 and walked into a giant wall after editing the touched event so it’s simply “Hit:Destroy()” and it takes me like 5 minutes to get into a position that actually destroys the giant wall

Hmm ok, that’s strange that it’s working for other things and not this specific one. There could be something subtle in your code that is modifying its behavior in an unexpected way. Could you try making this in a separate script and see if it works as expected? If so, there could be a hidden issue with the original that may be hard to catch.

If that doesn’t work, you could try re-scripting it one step at a time and testing it along the way to see if you can find the issue.

Worst case scenario, you could use the function to get all the parts in a box function. But I think one of the above things has a high chance of revealing the issue.

Hey, so I noticed in your hitbox you never determine the CFrame of it. And looks like you started the variable “boxOrientation” which looked like you were going to set the CFrame but forgot it!

This could be the issue as you created & made it in the workspace and everything but never knows where to place it exactly in the world…

			--adding hitbox to player
			local boxOrientation, boxSize = plr.Character:GetBoundingBox()
--/!!/  boxOrientation but not used for anything?
			local hitBox = Instance.new("Part")
			hitBox.CanCollide = false
			hitBox.Transparency = 1
			hitBox.Massless = true
			hitBox.Size = boxSize
			hitBox.Name = "finalSlashHitBox"
			hitBox.Parent = plr.Character
            hitBox.CFrame = boxOrientation --/!!/  this was missing!

This might not be the only issue but is definitely a fix to a problem as I saw you said

By which creating the hitbox so big to the point it has to be somewhere near enough no matter where the actual starting CFrame was, it would give you some kinda result sometimes.

I’ll keep that in mind, but when I tested it and selected the player the hitbox was all there?

I’ve done stuff where I set the CFrame of a part and then weld it to a part, and it goes straight to the part I welded, so I think that’s just how welding works, isn’t it? Or at least, in my experience, every time I weld something to the player it just appears on the center of the body part and to modify it’s CFrame I need to use C0