i have this script where it opens the door when a player steps on a part
local TweenService = game:GetService("TweenService")
-- [Constants] --
local Model = script.Parent
local Debounce = false
local Open = false
local CFValue = Model.CFrameValue
CFValue.Changed:Connect(function(Value)
Model:SetPrimaryPartCFrame(Value)
end)
local DoorTweenGoalOpen = TweenService:Create(CFValue, TweenInfo.new(1), {Value = Model.PrimaryPart.CFrame * CFrame.Angles(0, 90, 0)})
local DoorTweenGoalClose = TweenService:Create(CFValue, TweenInfo.new(1), {Value = Model.PrimaryPart.CFrame * CFrame.Angles(0, 0, 0)})
-- [Main] --
Model.Triggers.One.Touched:Connect(function(Hit)
if not Debounce then
if not Open then
Debounce = true
DoorTweenGoalOpen:Play()
Open = true
task.wait(1.2)
DoorTweenGoalClose:Play()
Open = false
Debounce = false
end
end
end)
This is because the CFrame value’s default position is 0,0,0. This will make the tween start on that position, set the CFrameValue value’s to the origin position of the model so it starts from there. CFrame.Angles() recieves numbers in radians, if you want to tween the door 90 degrees you will need to use math.pi/2 or math.rad(90). :SetPrimaryPartCFame() is deprecated, instead use :PivotTo() in replace of this function and :GetPivot() to get the model’s origin position. Also, TweenInfo’s default amount of seconds is 1, so there’s no need to define it as a paramater.
For last, this line of code will not work, since when you multiply CFrames you’re adding values, not setting them.
local TweenService = game:GetService("TweenService")
local Info = TweenInfo.new()
local Model = script.Parent
local CFValue = Model.CFrameValue
CFValue.Value = Model:GetPivot()
CFValue.Changed:Connect(function(Value)
Model:PivotTo(Value)
end)
local DoorTweenGoalOpen = TweenService:Create(CFValue, Info, {Value = Model:GetPivot() * CFrame.Angles(0, math.pi/2, 0)})
local DoorTweenGoalClose = TweenService:Create(CFValue, Info, {Value = CFrame.new(Model:GetPivot().p)})