Greetings everyone
So I have made this sliding door system for one of my projects.
The problem I have found its the tween slices the doors in the wrong way once the rotation/orientation is changed.
I have tried fixing the problem with the devforum solutions, but It keep refusing to tween the doors properly. I would be glad if anyone has a solution for this because I ran out of ideas.
Video: Sliding doors issue - Album on Imgur
Code:
--// SETTINGS
local OpenCloseTime = 3.3
--// VARIABLES
local Tweenservice = game:GetService("TweenService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local SecurityRemote = ReplicatedStorage:WaitForChild("SecurityDoor")
local Status = script.Parent:WaitForChild("Status")
local Door1, Door2 = script.Parent:WaitForChild("Door1"), script.Parent:WaitForChild("Door2")
local KeyHole = script.Parent:WaitForChild("Keyhole")
local IsBusy = script.Parent.IsBusy
local GateSound = Door1.Hinge:WaitForChild("GateSFX")
--// POSITIONS
local Door1Rotation = Door1.PrimaryPart.CFrame - Door1.PrimaryPart.CFrame.Position
local Door2Rotation = Door2.PrimaryPart.CFrame - Door2.PrimaryPart.CFrame.Position
local CFrameValue1 = Instance.new("CFrameValue", Door1)
local CFrameValue2 = Instance.new("CFrameValue", Door2)
CFrameValue1.Name = Door1.Name .. "'s CFrame"
CFrameValue2.Name = Door2.Name .. "'s CFrame"
CFrameValue1.Value = Door1:GetPivot()
CFrameValue2.Value = Door2:GetPivot()
local Door1OpenPos = Door1.PrimaryPart.CFrame * Door1Rotation + Vector3.new(0,0,-5)
local Door2OpenPos = Door2.PrimaryPart.CFrame * Door2Rotation + Vector3.new(0,0,5)
local Door1ClosePos = Door1.PrimaryPart.CFrame * Door1Rotation
local Door2ClosePos = Door2.PrimaryPart.CFrame * Door2Rotation
--// MAIN
CFrameValue1.Changed:Connect(function(Value)
Door1:PivotTo(Value)
end)
CFrameValue2.Changed:Connect(function(Value)
Door2:PivotTo(Value)
end)
Status.Changed:Connect(function()
if Status.Value == "Open" then
if IsBusy.Value == false then
IsBusy.Value = true
GateSound:Play()
KeyHole.Status.BrickColor = BrickColor.new("Black")
local Tween1 = Tweenservice:Create(CFrameValue1, TweenInfo.new(OpenCloseTime, Enum.EasingStyle.Linear, Enum.EasingDirection.Out), {Value = Door1OpenPos})
local Tween2 = Tweenservice:Create(CFrameValue2, TweenInfo.new(OpenCloseTime, Enum.EasingStyle.Linear, Enum.EasingDirection.Out), {Value = Door2OpenPos})
Tween1:Play()
Tween2:Play()
Tween1.Completed:Wait()
wait(2)
IsBusy.Value = false
KeyHole.Status.BrickColor = BrickColor.new("Lime green")
end
end
if Status.Value == "Close" then
if IsBusy.Value == false then
IsBusy.Value = true
GateSound:Play()
KeyHole.Status.BrickColor = BrickColor.new("Black")
local Tween1 = Tweenservice:Create(CFrameValue1, TweenInfo.new(OpenCloseTime, Enum.EasingStyle.Linear, Enum.EasingDirection.Out), {Value = Door1ClosePos})
local Tween2 = Tweenservice:Create(CFrameValue2, TweenInfo.new(OpenCloseTime, Enum.EasingStyle.Linear, Enum.EasingDirection.Out), {Value = Door2ClosePos})
Tween1:Play()
Tween2:Play()
Tween1.Completed:Wait()
wait(2)
IsBusy.Value = false
KeyHole.Status.BrickColor = BrickColor.new("Persimmon")
end
end
end)