How to detect multiple touches on a part

Hello, I’ve been trying for a while to make a type of crafting when player drops the item but I can’t even figure out how to detect 2 parts at the same time, this is what I’ve been trying out so far.

script.Parent.Touched:Connect(function(hit)
	if hit.Parent.Name == "Wood" and hit.Parent.Name == "Stone" then
		print("lol")
	end
end)
3 Likes

What is the item that the Touched is in?
Is this a crafting spot that the items get dropped on, or are you just dropping the items anywhere and trying to pick up what hits each other.

If it’s the first I’d look into using GetPartsInPart to see what’s in the crafting spot Part.

If it’s the second instead of getting the names of both hit items you could probably modify the Touched events. Check the Model Touched section of the Roblox documentation.

1 Like

Use GetTouchingParts and loop with for loop each items name.

1 Like

hit.Parent.Name is equal to Wood and Stone. To correct this you must do

script.Parent.Touched:Connect(function(hit)
	if hit.Parent.Name == "Wood" or hit.Parent.Name == "Stone" then
		print("lol")
	end
end)

This should combat your error.

1 Like
local touching = {}

script.Parent.Touched:Connect(function(hit)
	if hit.Parent.Name == "Wood" or hit.Parent.Name == "Stone" then
		-- Register as touching
		touching[hit] = hit.Parent.Name
	end

	local woodTouching, stoneTouching = false, false
	for _, other in touching do
		if other == "Wood" then
			woodTouching = true
		elseif other == "Stone" then
			stoneTouching = true
		end
		if woodTouching and stoneTouching then
			print("Both are touching!")
			break
		end
	end
end)

script.Parent.TouchEnded:Connect(function(hit)
	-- Not touching anymore
	touching[hit] = nil
end)
3 Likes

use workspace:GetPartBoundsInBox() what this does is detect objects inside the part.
/

script.Parent.Touched:Connect(function(hit)
	if hit.Parent.Name == "Wood" or hit.Parent.Name == "Stone" then
		local stuffInPart = workspace:GetPartBoundsInBox(-- stuff goes here)
		--your other stuff
	end
end)

Video Tutorial

2 Likes

One way to do it …

local wood=workspace:WaitForChild("wood")
local stone=workspace:WaitForChild("stone")
local db,set=true,false

wood.TouchEnded:Connect(function() set=false end)
wood.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		set=true
	end
end)

stone.TouchEnded:Connect(function() db=true end)
stone.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") and set and db then 
		db=false

		print("Touching both")

	end
end)
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.