Okay so I’m making a sliding door, but every time I activate it, it will teleport the model on top of the building, even though I have CanCollide for every single part off, when being moved. Here’s my code for opening and closing the door.
Open Door Code:
function OpenDoor()
door.PrimaryPart = door.Glass
cido.Value = true
script.Parent.col.BrickColor = acol
local cframe = door.PrimaryPart.CFrame -- Current CFrame
for i, v in pairs(door:GetChildren()) do
v.CanCollide = false
end
local vz = 0
for count = 1, 45 do
vz = vz - 0.007
local pos = Vector3.new(door.Glass.Position.X, door.Glass.Position.Y, door.Glass.Position.Z + vz)
door:MoveTo(pos)
wait(0.0000000000001)
end
end
Close Door Code:
function CloseDoor()
door.PrimaryPart = door.Glass
cido.Value = false
script.Parent.col.BrickColor = dcol
local cframe = door.PrimaryPart.CFrame -- Current CFrame
local vz = 0
for count = 1, 45 do
vz = vz - 0.007
local pos = Vector3.new(door.Glass.Position.X, door.Glass.Position.Y, door.Glass.Position.Z - vz)
door:MoveTo(pos)
wait(0.0000000000001)
end
for i, v in pairs(door:GetChildren()) do
v.CanCollide = true
end
end
I’m not sure if but maybe you will be disappointed when you rotate the door and the Z axis becomes the front and not the side, however I haven’t tested this and I’m not sure so don’t hold my word on it.
The function MoveTo was designed to increase the y axis if there was a part obstructing the space the model was trying to be placed in. You’ll have to use SetPrimaryPartCFrame if you want it to force it in that position.
If the model colliding is a problem , then make sure the Primary Part of a model is set, and it’s CanCollide property is set to false.
also as DesiredFlamingFire mentioned, use SetPrimaryPartCframe
Motor6Ds are more flexible with CFrame whereas welds aren’t on the same level. However, it entirely depends on what you want to achieve. For tweening a model, it doesn’t matter if you use welds or Motor6Ds unless you plan to add in animations to the model.