part.Touched is not detecting when a specific tool touches it

  1. What do you want to achieve?
    This script is located under a part. When the tool named “Chocolate Cookie Batter” touches the part, I want it to execute a function.

  2. What is the issue?
    It isn’t detecting when the tool touches the part.

local part = script.Parent
local detectorOne = part.Detector1
local detectorTwo = part.Detector2
local detectorThree = part.Detector3

local function cook(partThatTouched, newPartName, player)
	partThatTouched:Destroy()
	print("Cooking your food...")
	wait(5)
	print("Done!")
	
	local newPart = game.ReplicatedStorage.FoodItems.CookedTools[newPartName]:Clone()
	newPart.Parent = player.Backpack
end

detectorOne.Touched:Connect(function(hit)
	-- Here is where it doesn't work (can't detect the tool)
	if hit.Parent.Name == "Chocolate Cookie Batter" then
		print("It is a valid part")
		cook(hit.Parent, "Chocolate Cookie", game.Players:GetPlayerFromCharacter(hit.Parent.Parent))
	end
end)

Screenshot_11
Screenshot_12

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have tried searching in the DevForum and on Google but I couldn’t find anything.
2 Likes

Do both parts have CanTouch on?

Yes, both the handle and the detector have the CanTouch on.

Is the tool touching the correct part? you only have one .Touched event.
Try printing something when something touches it so you know atleast the .Touched event is working.

You’re checking the parent name of hit, (i think) you should’ve done:

hit.Parent:FindFirstChild("Chocolate Cookie Batter")

to get the tool

I tried it. It works with other parts. Here is a pic.

it’d be touching the handle, not the tool.

1 Like

I just realized that, my bad

charsss

1 Like

The Handle of the part should be the one that fires it. Not the tool itself.

Does it print when the handle touches it?

No, the handle isn’t printing.

Can you send me the .rbxl of your testing place?

Sure. Here is it.
kitchen_test.rbxl (48.3 KB)

It is a client sided tool, try to make it serversided so server scripts can detect it.

(You used a localscript to parent the tool to your backpack)

2 Likes

Thanks! It worked. I will change it later.