Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Help with detecting if a part is touching another part?

Asked by 6 years ago

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

Log in to vote
1
Answered by 6 years ago

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
Ad
Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

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.

Answer this question