Get touching parts not working

Hello! I’m currently trying to get my gun working after moving to a skinned rig, and i’ve encountered an issue where the hitbox registration no longer works! Could anyone help me with this?


(apologies with the messy code, i haven’t finalised it yet)

Server:

--> Variables
local Tool = script.Parent.Parent
local Structure = Tool:WaitForChild("Structure")
local Values = Tool:WaitForChild("Values")

--> Specific References
local Muzzle = Structure:WaitForChild("Muzzle")
local Particles = Muzzle:WaitForChild("ParticleEmitter")
local Sound = Muzzle:WaitForChild("Sound")
local Health = Values:WaitForChild("Health")
local Blur = Structure:WaitForChild("Blur")
local Fire = Structure:WaitForChild("Fire")
local Enabled = Values:WaitForChild("Enabled")
local Click = Tool.RemoteEvents.Click
local Left = Tool.RemoteEvents.Left

--> General Conditions
local PlayCo = false

--> Double checking that they're disabled!
Particles.Enabled = false

local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
raycastParams.FilterDescendantsInstances = {script.Parent.Parent.Parent}
raycastParams.IgnoreWater = true

--> Hitbox Initialisation
--Structure:WaitForChild("Hitbox").Touched:Connect(function() end)

--> let's make it work with the skinned rig

local Character = game.Workspace:WaitForChild(script.Parent.Parent.Parent.Parent.Name)

local function GetTouchingParts(part)
	local connection = part.Touched:Connect(function() end)
	local results = part:GetTouchingParts()
	connection:Disconnect()
	return results
end

Character.ChildAdded:Connect(function(child)
	if child:IsA("Tool") then
		if child.Name == "Flamethrower" then
			Enabled.Value = true
		end
	end
end)

Character.ChildRemoved:Connect(function(child)
	if child:IsA("Tool") then
		if child.Name == "Flamethrower" then
			Enabled.Value = false
		end
	end
end)

local Weld = Instance.new("WeldConstraint")
Weld.Parent = Character.Base:WaitForChild("ToolPoint")
Weld.Part0 = Character.Base:WaitForChild("ToolPoint")

local sw = coroutine.wrap(function()
	while task.wait(0.1) do
		script.Parent.Parent.Handle.Position = Character.Base:WaitForChild("ToolPoint").Position
		script.Parent.Parent.Handle.Orientation = Character.Base:WaitForChild("ToolPoint").Orientation + Vector3.new(0,90,0)
		--script.Parent.Parent.Handle.CFrame = CFrame.new(Character.Base:WaitForChild("ToolPoint").Position) * CFrame.Angles(0, math.rad(90), 0)
	end 
end)()
Weld.Part1 = script.Parent.Parent.Handle

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RaycastHitbox = require(ReplicatedStorage.RaycastHitboxV4)

--> Activated Tool Function
Click.OnServerEvent:Connect(function(Bool)
	print("Recieved")
	
	
	
	--> Running a new thread to determine the fuel left
	if PlayCo == false then
		PlayCo = true
		local Co2 = coroutine.wrap(function()
			while task.wait(0.1) do
				
				--> If the particles are enabled, we'll subtract a health
				if Particles.Enabled == true then
					Health.Value = Health.Value - 1
				end
				
				--> IIf the health is 0 or below, we'll destroy the tool
				if Health.Value <= 0 then
					Tool:Destroy()
					break
				end
				task.wait(0.1)
			end
		end)()
	end
	
	--> Enabling Visual Effects
	Particles.Enabled = true
	Particles.Parent.Sound:Play()
	
	--local OverlapParams1 = OverlapParams.new()
	
	--> Looping for particles enabled
	while Particles.Enabled == true do
		
		--[[
		local raycastResult = workspace:Raycast(Structure.Hitbox.Position, Structure.Hitbox.CFrame.LookVector * 5, raycastParams)
		print(raycastResult)
		task.wait(0.1)
		--]]

		--> Getting the parts touching!
		local Parts = Structure.Hitbox:GetTouchingParts()
		local Humanoids_Damaged = {}
		
		print("Got Touched")
		
		print(Parts)
		
		--> Prevents crashing by an overly quick loop, while still not feeling clunky
		task.wait(0.1)
		
		
		--> Looping through the touched parts
		for i, Part in pairs(Parts) do
			
			print(Part)
			
			--> Seeing if it's a humanoid!
			if Part.Parent:FindFirstChild("Humanoid") and not Humanoids_Damaged[Part.Parent.Humanoid] then
				
				print("Found humanoid!")
				Humanoids_Damaged[Part.Parent.Humanoid] = true
				
				--> Running a new thread so we don't abstain the rest
				local Co = coroutine.wrap(function()
					local Number
					
					--> Checking if they're already on fire
					if Part.Parent.Humanoid:FindFirstChild("NumberValue") then
						Number = Part.Parent.Humanoid:FindFirstChild("NumberValue")
					else
						Number = Instance.new("NumberValue")
						Number.Parent = Part.Parent.Humanoid
					end
					
					Number.Value = 15
					
					--> Initialising the fire effect
					local D1 = Fire:Clone()
					local D2 = Blur:Clone()
					
					--> Parenting the effect to make it visual
					D1.Parent = Part.Parent.HumanoidRootPart
					D2.Parent = Part.Parent.HumanoidRootPart
					
					--> Dealing Gradual Damage
					while Number.Value > 0 do
						task.wait(0.1)
						Number.Value -= 1
						Part.Parent.Humanoid:TakeDamage(1)
					end
					
					--> The fire effect is over
					D1:Destroy()
					D2:Destroy()

				end)()
			end
		end
					--]]
	end
end)

--> When deactivated, we'll stop the effects
Left.OnServerEvent:Connect(function()
	print("left")
	Particles.Enabled = false
	Particles.Parent.Sound:Stop()
end)

client

local Tool = script.Parent.Parent
local Values = Tool:WaitForChild("Values")
local Enabled = Values:WaitForChild("Enabled")
local UserInputService = game:GetService("UserInputService")
local Click = Tool.RemoteEvents.Click
local Left = Tool.RemoteEvents.Left

UserInputService.InputBegan:Connect(function(inputObject)
	if inputObject.UserInputType == Enum.UserInputType.MouseButton1 then
		if Enabled.Value == true then
			Click:FireServer()
		end
	end
end)

UserInputService.InputEnded:Connect(function(inputObject)
	if inputObject.UserInputType == Enum.UserInputType.MouseButton1 then
		if Enabled.Value == true then
			Left:FireServer()
		end
	end
end)

Thanks in advance!

1 Like

Is the object anchored? If yes use workspace:GetPartsInPart(part1) instead.

local UIS = game:GetService("UserInputService")

local Handle = script.Parent
local Tool = Handle.Parent
local Events = Tool:WaitForChild("RemoteEvents")
local Click = Events:WaitForChild("Click")
local Left = Events:WaitForChild("Left")
local Values = Tool:WaitForChild("Values")
local Enabled = Values:WaitForChild("Enabled")

UIS.InputBegan:Connect(function(inputObject, gameProcessedEvent)
	if gameProcessedEvent then
		return
	end
	
	if inputObject.UserInputType == Enum.UserInputType.MouseButton1 then
		if Enabled.Value then
			Click:FireServer()
		end
	end
end)

UIS.InputEnded:Connect(function(inputObject, gameProcessedEvent)
	if gameProcessedEvent then
		return
	end
	
	if inputObject.UserInputType == Enum.UserInputType.MouseButton1 then
		if Enabled.Value then
			Left:FireServer()
		end
	end
end)

The local script seems fine, I’ve just added game processed input checks. This works if placed inside the “Handle” BasePart instance of the tool.

local RS = game:GetService("ReplicatedStorage")
local Module = RS:WaitForChild("RaycastHitboxV4")
local RaycastHitbox = require(Module)

local Player = script:FindFirstAncestorWhichIsA("Player")
local Character = Player.Character or Player.CharacterAdded:Wait()
local Base = Character:WaitForChild("Base")
local TP = Base:WaitForChild("ToolPoint")

local Handle = script.Parent
local Tool = Handle.Parent
local Events = Tool:WaitForChild("RemoteEvents")
local Click = Events:WaitForChild("Click")
local Left = Events:WaitForChild("Left")
local Values = Tool:WaitForChild("Values")
local Enabled = Values:WaitForChild("Enabled")
local Structure = Tool:WaitForChild("Structure")
local Muzzle = Structure:WaitForChild("Muzzle")
local Particles = Muzzle:WaitForChild("ParticleEmitter")
Particles.Enabled = false
local Sound = Muzzle:WaitForChild("Sound")
local Health = Values:WaitForChild("Health")
local Blur = Structure:WaitForChild("Blur")
local Fire = Structure:WaitForChild("Fire")
local Hitbox = Structure:WaitForChild("Hitbox")

local PlayCo = false

local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
raycastParams.FilterDescendantsInstances = {Character}
raycastParams.IgnoreWater = true

Hitbox.Touched:Connect(function(_)
	return
end)

local function GetTouchingParts(part)
	local connection = part.Touched:Connect(function() end)
	local results = part:GetTouchingParts()
	connection:Disconnect()
	return results
end

Character.ChildAdded:Connect(function(child)
	if child:IsA("Tool") then
		if child.Name == "Flamethrower" then
			Enabled.Value = true
		end
	end
end)

Character.ChildRemoved:Connect(function(child)
	if child:IsA("Tool") then
		if child.Name == "Flamethrower" then
			Enabled.Value = false
		end
	end
end)

local Weld = Instance.new("WeldConstraint")
Weld.Parent = TP
Weld.Part0 = TP

local sw = coroutine.wrap(function()
	while task.wait(0.1) do
		Handle.Position = TP.Position
		Handle.Orientation = TP.Orientation + Vector3.new(0,90,0)

	end 
end)()

Weld.Part1 = Handle

Click.OnServerEvent:Connect(function()
	print("Recieved")
	if not PlayCo then
		PlayCo = true
		local Co2 = coroutine.wrap(function()
			while task.wait(0.1) do
				if Particles.Enabled then
					Health.Value -= 1
				end

				if Health.Value <= 0 then
					Tool:Destroy()
					break
				end
				task.wait(0.1)
			end
		end)()
	end

	Particles.Enabled = true
	Sound:Play()
	while Particles.Enabled do
		local raycastResult = workspace:Raycast(Hitbox.Position, Hitbox.CFrame.LookVector * 5, raycastParams)
		print(raycastResult)
		task.wait(0.1)
		local Parts = Hitbox:GetTouchingParts()
		local Humanoids_Damaged = {}
		print("Got Touched")
		print(Parts)
		task.wait(0.1)
		for i, Part in pairs(Parts) do
			print(Part)
			local Humanoid = Part.Parent:FindFirstChild("Humanoid")
			if Humanoid then
				local HRP = Part.Parent:FindFirstChild("HumanoidRootPart")
				if not Humanoids_Damaged[Humanoid] then
					print("Found humanoid!")
					Humanoids_Damaged[Humanoid] = true
					local Co = coroutine.wrap(function()
						local Number

						if Humanoid:FindFirstChild("NumberValue") then
							Number = Humanoid:FindFirstChild("NumberValue")
						else
							Number = Instance.new("NumberValue")
							Number.Parent = Humanoid
						end

						Number.Value = 15
						local D1 = Fire:Clone()
						local D2 = Blur:Clone()
						D1.Parent = HRP
						D2.Parent = HRP

						while Number.Value > 0 do
							task.wait(0.1)
							Number.Value -= 1
							Humanoid:TakeDamage(1)
						end

						D1:Destroy()
						D2:Destroy()
					end)()
				end
			end
		end
	end
end)

This was the server script I came up with.

https://developer.roblox.com/en-us/api-reference/function/BasePart/GetTouchingParts

Remember that if CanCollide is disabled then GetTouchingParts() will return an empty table unless a TouchTransmitter instance is parented to the BasePart object through which GetTouchingParts() is being called.

Hitbox.Touched:Connect(function(_)
	return
end)

I’ve added this block of code to combat this.

This should also be parented to the “Handle” BasePart inside the Tool instance.

it isn’t, atleast the tool isn’t

Thanks for the response, however, the same issue still occurs

Both parts have to be unanchored to get it working. I assume the dummy “HumanoidRootPart” anchored property is set to true, which you are searching for inside your code.