I have a blast door, and 2 door models inside it, and I wanna move them so that the door is opened. The position is moving correct, but also it rotates the door 90 degrees when opening. And it does not rotate it -90 degrees when closing.
I know the issue, it’s because CFrameValue that gets created has orientation of 0,0,0. How to set it to 0,90,0?
This issue is causing me to go insane, please help.
The clear code:
local TweenService = game:GetService("TweenService")
local Info = TweenInfo.new(12.91)
local Door1 = script.Parent.Door1
local Door2 = script.Parent.Door2
local TweenedCompleted = "N/A"
local DoorStatus = "Closed"
local DoorLocked = false
local Remote = Instance.new("BindableEvent",script.Parent)
local Debounce = false
local De
local function TweenModel(Model, CFrame, Wait)
local CFrameValue = Instance.new("CFrameValue")
CFrameValue.Value = Model:GetPrimaryPartCFrame()
CFrameValue:GetPropertyChangedSignal("Value"):connect(function()
Model:SetPrimaryPartCFrame(CFrameValue.Value)
end)
local Tween = TweenService:Create(CFrameValue, Info, {Value = CFrame})
Tween:Play()
Tween.Completed:connect(function()
CFrameValue:Destroy()
TweenedCompleted = "Yes"
end)
while TweenedCompleted == "N/A" and Wait == true do
wait(0.1)
end
TweenedCompleted = "N/A"
end
local function Open()
TweenModel(script.Parent.Door1, CFrame.new(script.Parent.Door1.Center.Position.X,script.Parent.Door1.Center.Position.Y,script.Parent.Door1.Center.Position.Z + 8),false)
TweenModel(script.Parent.Door2,CFrame.new(script.Parent.Door2.Center.Position.X,script.Parent.Door2.Center.Position.Y,script.Parent.Door2.Center.Position.Z - 8),true)
DoorStatus = "Opened"
end
local function Close()
TweenModel(script.Parent.Door1, CFrame.new(script.Parent.Door1.Center.Position.X,script.Parent.Door1.Center.Position.Y,script.Parent.Door1.Center.Position.Z - 8),false)
TweenModel(script.Parent.Door2,CFrame.new(script.Parent.Door2.Center.Position.X,script.Parent.Door2.Center.Position.Y,script.Parent.Door2.Center.Position.Z + 8),true)
DoorStatus = "Closed"
end
--[[Removed the triggers for easier read on forum]]--
It seems like the rotation issue you’re facing is due to the orientation of the CFrameValue not being set correctly. To fix this, you can adjust the orientation of the CFrameValue to match the desired rotation of the door.
Here’s how you can modify your TweenModel function to set the orientation of the CFrameValue to 0, 90, 0:
local function TweenModel(Model, CFrame, Wait)
local CFrameValue = Instance.new("CFrameValue")
CFrameValue.Value = Model:GetPrimaryPartCFrame()
-- Set the orientation of the CFrameValue
CFrameValue.Value = CFrameValue.Value * CFrame.Angles(0, math.rad(90), 0)
CFrameValue:GetPropertyChangedSignal("Value"):connect(function()
Model:SetPrimaryPartCFrame(CFrameValue.Value)
end)
local Tween = TweenService:Create(CFrameValue, Info, {Value = CFrame})
Tween:Play()
Tween.Completed:connect(function()
CFrameValue:Destroy()
TweenedCompleted = "Yes"
end)
while TweenedCompleted == "N/A" and Wait == true do
wait(0.1)
end
TweenedCompleted = "N/A"
end
This modification should ensure that the doors rotate correctly when opening and closing. If you encounter any further issues or have any questions, feel free to ask!
What @MochaTheDev gave you should work. The reason an error occurs is because your function has a parameter with the same name as the datatype (CFrame). Whenever you put:
CFrame.Angles
It refers to the CFrame parameter, not the data type. Just change the name.