I just want to make a prompt door that opens correctly to the side you’re facing, but if I rotate the door it completely breaks and either doesn’t open or open too far, the hinge rotation for some reason doesnt correspond with the goal
Door script
local door = script.Parent
local hinge = door:WaitForChild("DoorHinge")
local origin = hinge.Rotation
local originCfr = hinge.CFrame
local ts = game:GetService("TweenService")
local info = TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut)
local opened = false
print(origin)
for _, prompt in pairs(door:GetDescendants()) do
if prompt:IsA("ProximityPrompt") then
prompt.Triggered:Connect(function()
if not opened then
opened = true
if prompt.Parent.Name == "OpenFromIn" then
local goal = {}
goal.CFrame = hinge.CFrame * CFrame.Angles(0, math.rad(origin.Y - 90), 0)
print(origin.Y - 90, "-- goal")
local tween = ts:Create(hinge, info, goal)
for _, prompt in pairs(door:GetDescendants()) do
if prompt:IsA("ProximityPrompt") then
prompt.Enabled = false
end
end
tween:Play()
tween.Completed:Wait()
print(hinge.Orientation, "--end orientation")
for _, prompt in pairs(door:GetDescendants()) do
if prompt:IsA("ProximityPrompt") then
prompt.Enabled = true
prompt.ActionText = "Close"
end
end
elseif prompt.Parent.Name == "OpenFromOut" then
local goal = {}
goal.CFrame = hinge.CFrame * CFrame.Angles(0, math.rad(origin.Y + 90), 0)
print(origin.Y + 90, "-- goal")
local tween = ts:Create(hinge, info, goal)
for _, prompt in pairs(door:GetDescendants()) do
if prompt:IsA("ProximityPrompt") then
prompt.Enabled = false
end
end
tween:Play()
tween.Completed:Wait()
print(hinge.Orientation, "-- end orientation")
for _, prompt in pairs(door:GetDescendants()) do
if prompt:IsA("ProximityPrompt") then
prompt.Enabled = true
prompt.ActionText = "Close"
end
end
end
elseif opened then
opened = false
local goal = {}
goal.CFrame = originCfr
local tween = ts:Create(hinge, info, goal)
for _, prompt in pairs(door:GetDescendants()) do
if prompt:IsA("ProximityPrompt") then
prompt.Enabled = false
end
end
tween:Play()
tween.Completed:Wait()
opened = false
for _, prompt in pairs(door:GetDescendants()) do
if prompt:IsA("ProximityPrompt") then
prompt.Enabled = true
prompt.ActionText = "Open"
end
end
end
end)
end
end
this singlehandedly makes me not want to continue this project so help would be appreciated