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

Teleported part not firing touched event?

Asked by 8 years ago

Howdy. I have a part (call it part A) that is inside a doorway of sorts. Another script teleports a new part (call it part B) inside of part A.

Part A has the following script:

01function onTouch(part)
02wait()
03print("Touched")
04if part.Parent.Name == "Room" then
05    print("Room")
06    script.Parent.Parent.OpenEnds.Value = script.Parent.Parent.OpenEnds.Value - 1
07    script.Parent:Destroy()
08end
09end
10script.Parent.Touched:connect(onTouch)

The code that teleports part B into part A:

1roomModel.Parent = game.Workspace
2--roomModel:MoveTo(position)
3roomModel:SetPrimaryPartCFrame(CFrame.new(position))
4if roomModel.PrimaryPart.Position.Y > script.Parent.Position.Y then
5    roomModel:Destroy()
6end

The way part B is teleported is in a SetPrimaryPartCFrame. As a result, part B teleports inside part A. The problem I am having is that it seems that the onTouch function is not firing, as neither "Touched" nor "Room" print. Even though part B is CFramed into part A, part A's script does not register them as touching. Thanks in advance.

1 answer

Log in to vote
0
Answered by 8 years ago
Edited 8 years ago

I believe Touched doesn't run if it's directly tp'ed in the part , try using magnitude?

Ad

Answer this question