Part detecting touches on everything put characters?

Alright, I’m really stuck on this one, for some reason, my punching is detecting hit’s on EVERYTHING BUT OTHER PLAYERS. Now Idk why this is happening, however, I even tried welding a hitbox to every player BUT STILL it won’t detect those. Now, I have some hitboxes for training zones and those will be detected but not characters???

Code, Local Script (in the Punch tool)

--// Services
local Players = game:GetService("Players")
local RS = game:GetService("ReplicatedStorage")

--// Remote Folders
local Remotes = RS.Remotes
local RemoteEvents = Remotes.Events
local ServerEvents = RemoteEvents.Server
local ToolEvents = ServerEvents.ToolEvents

--// Remote Events
local PunchEvent = ToolEvents.Punch

--// Variables
local Tool = script.Parent
local Debounce = false

--// Character Variables
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()

-- Animation Vars
local Humanoid = Character:WaitForChild("Humanoid")
local Animator = Humanoid:WaitForChild("Animator")

local Punch1Anim = Instance.new("Animation")
Punch1Anim.AnimationId = "rbxassetid://10605741632"
local Punch1AnimTrack = Animator:LoadAnimation(Punch1Anim)
Punch1AnimTrack.Priority = Enum.AnimationPriority.Action
Punch1AnimTrack.Looped = false
Punch1AnimTrack:AdjustSpeed(1)

local Punch2Anim = Instance.new("Animation")
Punch2Anim.AnimationId = "rbxassetid://10605769375"
local Punch2AnimTrack = Animator:LoadAnimation(Punch2Anim)
Punch2AnimTrack.Priority = Enum.AnimationPriority.Action
Punch2AnimTrack.Looped = false
Punch2AnimTrack:AdjustSpeed(1)

local AnimToPlayNext = Punch1AnimTrack

--// Punch 1 10605741632
--// Punch 2 10605769375


--// Functions
local function NextAnim()
	if AnimToPlayNext == Punch1AnimTrack then
		AnimToPlayNext = Punch2AnimTrack
	elseif AnimToPlayNext == Punch2AnimTrack then
		AnimToPlayNext = Punch1AnimTrack
	end
end

local function OnToolActiaved()
	if Debounce == false then
		Debounce = true
		
		AnimToPlayNext:Play()
		NextAnim()
		
		PunchEvent:FireServer()
		
		task.delay(1, function()
			print("Debounce reset")
			Debounce = false
		end)
	end
end

--// Connections
Tool.Activated:Connect(OnToolActiaved)

The 2 functions in the server script that handle the damaging.

local function DealDamage(Dealer: Player, Parts: {}, BaseDmg: number, PowersMulti: number)
	for _, Part: BasePart in Parts do
		local Player = Players:GetPlayerFromCharacter(Part.Parent)
		if Player then
			local Char = Player.Character
			if not Char then continue end
			
			local Human = Char.Humanoid
			Human:TakeDamage(CalcDamage(Dealer, BaseDmg, PowersMulti))
		end
	end
end

local function DetectDamage(Player)
	local Character = Player.Character or Player.CharacterAdded:Wait()
	local RightHand, LeftHand = Character.RightHand, Character.LeftHand
	
	local PartsTouchingRightHand, PartsTouchingLeftHand = RightHand:GetTouchingParts(), LeftHand:GetTouchingParts()
	
	print(PartsTouchingRightHand, PartsTouchingLeftHand)
	
	local PartsAreTouchingRight, PartsAreTouchingLeft = #PartsTouchingRightHand > 0, #PartsTouchingLeftHand > 0
	
	if PartsAreTouchingLeft then
		print("Left Hand Hit", PartsTouchingLeftHand)
		DealDamage(Player, PartsTouchingLeftHand, 1, 1)
	elseif PartsAreTouchingRight then
		DealDamage(Player, PartsTouchingRightHand, 1, 1)
		print("Right hand hit", PartsTouchingRightHand)
	end
end

(BTW, workspace:GetPartsInPart(RightHand, OverlapParams.new()) doesnt work either!)

Any help?

2 Likes

workspace:GetPartsInPart most likely does not work because it is now deprecated

GetTouchingParts only detect parts that collide with the Part WITH collision ON.

This seems false, as I mentioned, it detects hit’s with my hitbox which is also CanCollide = false, however, on both, CanTouch = true

It still works on everything BUT the char, plus my code doesn’t used that, I just mentioned I tried it.

GetTouchingParts only gets Parts with CanCollide on.

Clearly not, as long as CanTouch = true it should still work. Like I mentioned above, it detects hit’s on a hitbox (not for the character) that ALSO has CanCollide = false

Any help, please? I would appreciate it!

No. It NEEDS to have CanCollide On to detect any Parts inside it. CanTouch doesn’t affect GetTouchingParts at all. This even mentioned in the Docs.

Returns a table of all parts that are physically interacting with this part. If the part itself has CanCollide set to false, then this function will return an empty table UNLESS it has a TouchInterest

Alright, now I have 2 questions:

  1. Why does it detect the hit box for other things that ALSO have CanCollide set to false
  2. What would be the best way to detect the punches in that case
  1. That touching rule only applies to the Part which you ate callimg GetTouchingParts() to.
  2. The best replacement would be workspace:GetPartsInPart().
local function DealDamage(Dealer: Player, Parts: {}, BaseDmg: number, PowersMulti: number)
	for _, Part: BasePart in Parts do
		local Player = Players:GetPlayerFromCharacter(Part.Parent)
		if Player then
			local Char = Player.Character
			
			local Human = Char:FindFirstChildOfClass("Humanoid")
			if Human then
               Human:TakeDamage(CalcDamage(Dealer, BaseDmg, PowersMulti))
			end			
		end
	end
end

local function DetectDamage(Player)
	local Character = Player.Character
        if not Character then
            return nil
        end
	local RightHand, LeftHand = Character:FindFirstChild("RightHand"), Character:FindFirstChild("LeftHand")
	
	local PartsTouchingRightHand, PartsTouchingLeftHand = workspace:GetPartsInPart(RightHand), workspace:GetPartsInPart(LeftHand)
	
	print(PartsTouchingRightHand, PartsTouchingLeftHand)
	
	local PartsAreTouchingRight, PartsAreTouchingLeft = #PartsTouchingRightHand > 0, #PartsTouchingLeftHand > 0
	
	if PartsAreTouchingLeft then
		print("Left Hand Hit", PartsTouchingLeftHand)
		DealDamage(Player, PartsTouchingLeftHand, 1, 1)
	elseif PartsAreTouchingRight then
		DealDamage(Player, PartsTouchingRightHand, 1, 1)
		print("Right hand hit", PartsTouchingRightHand)
	end
end

I don’t get what you mean by that because BOTH times, when I punch the character or punch where the hit box is, their both CanCollide off

I’ll try that again, but like I mentioned in the OG post:

And it once again only detected the hit box

Interesting… it worked! Thanks a lot first of all.
I have a question tho

Did it not work because I added OverlapParams.new() or any other reason it would only detect the hitbox?