Im using tweening to close/open the doors and for some reason the only parts that get moved is the part i actually tweened. Ive tried welds and weld constraints, Ive tried unanchoring the welded objects. The weirdest part about this is the fact it works perfectly on client but not ServerSide.
Please can someone help me out as i have no idea what to do next.
function openDoors(door)
door.Sounds.Open:play()
door.Sounds.Moving:play()
local TweenService = game:GetService("TweenService")
local part = door.Door1.door
part.Position = door.Start1.Position
local goal = {}
goal.Position = door.End1.Position
local tweenInfo = TweenInfo.new(5)
local tween = TweenService:Create(part, tweenInfo, goal)
tween:Play()
local TweenService = game:GetService("TweenService")
if door:FindFirstChild("Door2") then
local part = door.Door2.door
part.Position = door.Start2.Position
local goal = {}
goal.Position = door.End2.Position
local tweenInfo = TweenInfo.new(5)
local tween = TweenService:Create(part, tweenInfo, goal)
tween:Play()
end
tween.Completed:Connect(function()
door.Sounds.Moving:Stop()
door.Sounds.Close:play()
end)
end
This is a little bit off topic, but I wanted to give a few pointers after reviewing your code, it is very messy(I’m sure you noticed it as well).
Your GetServices variables should be stored outside functions/loops as well as your tween.info to save time. Basically anything that gets reused multiple times should be outside these functions
Aldo I noticed you called GetService(“TweenService”) twice, which is strange and not needed since you already called the service the first time.
Also I dont think you need to verify if the door exists since it already exists so you should just remove it (Unless the door can be destroyed and respawned then you should do this). You did it fine the first time for Door1 so it’s a little bit confusing why you did it for Door2
local TweenService = game:GetService("TweenService")
local doorPart1 = door.Door1.door
local doorPart2 = door.Door2.door
function openDoors(door)
local goal = {}
-- Door 1 tweens
door.Sounds.Open:play()
door.Sounds.Moving:play()
doorPart1.Position = door.Start1.Position
goal.Position = door.End1.Position
local tweenInfo = TweenInfo.new(5) -- you should also create tweenInfo1 and tweenInfo2 for this as well
local tween = TweenService:Create(part, tweenInfo, goal)
tween:Play()
-- Door 2 tweens
part.Position = door.Start2.Position
goal.Position = door.End2.Position
local tweenInfo = TweenInfo.new(5)
local tween = TweenService:Create(part, tweenInfo, goal)
tween:Play()
tween.Completed:Connect(function()
door.Sounds.Moving:Stop()
door.Sounds.Close:play()
end)
end
As for your problem I’m not too sure what the problem is, I need to test this my self, Ill get back to you if I can find an answer
(Aplogies for any mistakes in the code above, im on mobile rn and its a bit hard to type)
Position overides behavior of welds;
Please use CFrame instead and please put values dirrectly inside table there so table will not have to be expanded multiple times during runtime.
All the parts that move with the part you’re tweening should not be anchored (even massless) and they are all welded to the moving part (or welded together with one welded to the moving part).
This a good chance to go generic, so it can be used on any door set up that is the same.
function openDoors(gate)
local doorPart1 = gate.Door1.door
local doorPart2 = gate.Door2.door
gate.Sounds.Open:Play()
gate.Sounds.Moving:Play()
doorPart1.Position = gate.Start1.Position
local t1 = TweenService:Create(doorPart1, TweenInfo.new(5), {Position = gate.End1.Position})
t1:Play()
doorPart2.Position = gate.Start2.Position
local t2 = TweenService:Create(doorPart2, TweenInfo.new(5), {Position = gate.End2.Position})
t2:Play()
t2.Completed:Wait()
gate.Sounds.Moving:Stop()
gate.Sounds.Close:Play()
end
It works passing door like you had it, but you’re also using door in the path.
It bugs me to do that , so I went with gate. Also use one of them weld plugins.