-
What do you want to achieve? Keep it simple and clear!
I would like to fix my door opening tween script. -
What is the issue? Include screenshots / videos if possible!
Some parts of the door go weird when it rotates. Also my door is a model and it is all anchored with no welds and it is placed on an attachment (For my placement system) and it rotates around the attachment. Here is a video of my issue happening :
-
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I have looked for solutions on DevForum and on YT and tried ChatGPT but still nothing.
Here is my code :
local TweenService = game:GetService("TweenService")
local clickDetector = script.Parent
local model = script.Parent.Parent.Parent
local attachmentPart = clickDetector.Parent
local doorSound = attachmentPart:WaitForChild("DoorSound")
local attachment = attachmentPart:FindFirstChild("DoorSnapAttachment")
local primaryPart = model.PrimaryPart
local tweenInfo = TweenInfo.new(
1,
Enum.EasingStyle.Linear,
Enum.EasingDirection.Out,
0,
false,
0
)
local open = false
local deb = false
clickDetector.MouseClick:Connect(function(player)
if model and attachment then
if deb == false then
local attachmentPosition = attachment.WorldPosition
doorSound:Play()
deb = true
if open == false then
open = true
for _, part in ipairs(model:GetDescendants()) do
if part:IsA("BasePart") then
local currentCFrame = part.CFrame
local rotationCFrame = CFrame.new(attachmentPosition) * CFrame.Angles(0, math.rad(90), 0)
local goalCFrame = rotationCFrame * (currentCFrame - attachmentPosition)
local tweenGoal = { CFrame = goalCFrame }
local tween = TweenService:Create(part, tweenInfo, tweenGoal)
tween:Play()
end
end
else
open = false
for _, part in ipairs(model:GetDescendants()) do
if part:IsA("BasePart") then
local currentCFrame = part.CFrame
local rotationCFrame = CFrame.new(attachmentPosition) * CFrame.Angles(0, math.rad(-90), 0)
local goalCFrame = rotationCFrame * (currentCFrame - attachmentPosition)
local tweenGoal = { CFrame = goalCFrame }
local tween = TweenService:Create(part, tweenInfo, tweenGoal)
tween:Play()
end
end
end
task.wait(1.5)
deb = false
end
end
end)