Get touching parts not working

What I’m trying to do is make it so that when the clickdetector is pressed, any player who is touching “Part1” will be teleported to “Part2” but nothing happens. All help appreciated!

script.Parent.ClickDetector.MouseClick:Connect(function()
	local parts = game.Workspace.Part1:GetTouchingParts()
	for _, part in next, parts do
		if part.Parent:FindFirstChild("Humanoid") then
			part.Parent.HumanoidRootPart.CFrame = game.Workspace.Part2.CFrame
		end
	end
end)
1 Like

if the part is uncancollide then :GetTouchingParts() will not work on it unless you add a touchinterest which you also cannot create with Instance.new(), you must do the following if this is your issue

Part.Touched:Connect(function() end)
-- before :GetTouchingParts() is used
13 Likes

GetTouchingParts() doesn’t work on non-cancollide parts, which includes the legs of the players. It would be better to use a Region3 | Roblox Creator Documentation. You can create a region the size and position of Part1 with

local p = workspace.Part1.Position
local s = workspace.Part1.Size
local region = Region3.new(Vector3.new(p.X-s.X/2, p.Y-s.Y/2, p.Z-s.Z/2), Vector3.new(p.X+s.X/2, p.Y+s.Y/2, p.Z+s.Z/2))

and then detect parts within that region with Workspace | Roblox Creator Documentation

local parts = workspace:FindPartsInRegion3(region)

However, to answer your question about making GetTouchingParts() register on players you can look at this community resource. This is the same answer that @Synergious gave but remember to disconnect the Touched connection when you’re done to prevent memory leaks!

2 Likes

it does if you add a touchinterest, that’s when i stated add:

Part.Touched:Connect(function() end)

since it’s not creatable from Instance.new(), but it does just depend on what he is trying to do

1 Like

Id like to express my displeasure with learning the information that GetTouchingParts() will not activate with parts that have can collide turned off and will now cry for 30 minutes, good day.