Using a BasePart Touched event doesn't print any objects even if it hits one

I am creating a hitbox that moves 100 studs in front of a player’s HumanoidRootPart and if this hitbox touches anything when it’s in motion, it will print the objects name.

I am using this in a server script and the Touched event doesn’t print anything if it comes into contact with an object…

local TweenService = game:GetService("TweenService")
local DebrisService = game:GetService("Debris")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local ServerCommunication = ReplicatedStorage:WaitForChild("ServerCommunication")
local Hitbox = script.Hitbox
local Cooldown = 5
local Debounce = {}

local function RecieveSignal(Player)
	if table.find(Debounce, Player.Name) then
		print("Player is on a cooldown!")
	else
		local Character = Player.Character

		local NewHitbox = Hitbox:Clone()
		NewHitbox.CFrame = Character.HumanoidRootPart.CFrame * CFrame.new(0, 0, -4)
		NewHitbox.Parent = workspace

		DebrisService:AddItem(NewHitbox, 1)

		TweenService:Create(
			NewHitbox,
			TweenInfo.new(1),
			{Position = Character.HumanoidRootPart.CFrame * CFrame.new(0, 0, -100).Position}
		):Play()

		NewHitbox.Touched:Connect(function(Hit)
			if not Hit:IsDescendantOf(Character) then
				local Humanoid = Hit.Parent:FindFirstChild("Humanoid")
				
				if Humanoid then
					if Humanoid:FindFirstChild(Player.Name .. "HitboxCooldown") then
						print("Player has already been damaged")
					else
						Humanoid:TakeDamage(5)
						
						local HitboxCooldown = Instance.new("BoolValue")
						HitboxCooldown.Name = Player.Name .. "HitboxCooldown"
						HitboxCooldown.Parent = Humanoid
						
						DebrisService:AddItem(HitboxCooldown, 3)
					end					
				end
			end
		end)

		table.insert(Debounce, Player.Name)
		task.wait(Cooldown)
		Debounce[table.find(Debounce, Player.Name)] = nil	
	end
end

ServerCommunication.OnServerEvent:Connect(RecieveSignal)

I honestly don’t know why this is happening, my best guess is the TweenService is stopping it from running, but I put the touched event in a thread and it still didn’t work.

The part’s properties:
image

Update: Once I remove the TweenService part of the script and my character touches the part, it works. No idea what’s happening here, I need it to work in motion and if it hits anything else.

Touched doesn’t fire on BasePart instances if their “CanCollide” property is disabled.

It does. Did you mean CanTouch?

The BasePart requires a TouchTransmitter instance as well.

I tested it with CanCollide enabled aswell. It didn’t work.

Let me know if I understood you correctly.
You basically use TweenService to move the part towards the player?

If you do, then Touched event does not fire when an anchored part moves.

No, the part is being created 4 studs infront of the player and and propelled 100 studs from that point. If it comes into contact with anything it should damage that object if it has a humanoid and hasnt already been damaged.

And why would .Touched not work if the part is anchored?

What the! That actually fixed it.

1 Like