Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Help with detecting if a part is touching another part?

I have a part, and I want to make it so that when it touches a specific other part called "Thing" the part that touched "Thing" will teleport.

scipt.Parent.Touched:Connect(function(hit)
script.Parent.Position = Cframe.new(453,68,926)
end)

This code makes it so it teleports whenever it touches any part and not just when it touches "Thing"

2 answers

this may help just use the name of the part and on the first line you forgot to add the r in front of and CFrame is spelled CFrame not Cframe but this might work:

script.Parent.Touched:Connect(function(hit)
	if hit.name == "Thing" --put name here
		then 
		script.Parent.Position = CFrame.new(453,68,926) 
	end

end)

--your welcome, Jimonogamer

##Just use an if Statement

local part = "Thing" --The name of the expected part
local pos = "453,68,926" --Teleport Position

script.Parent.Touched:Connect(function(hit) --Runs on touch
	if hit.Name == part then --Checks if the touched part is expected part
		script.Parent.Position = Vector3.new(pos) --If yes then teleports to selected position
	end --End of if Statement
end) --End of function

And it's done.

Edit : Your script had lots of mistakes.

This discussion is preserved as it was. New answers, comments, and votes are closed.