[SOLVED] Help with my Power Box Door script

I’m making a game, i’m coding a power box via cframe angles. But how can i make when the door closes, the position get back to normal?

Here’s an example of the bug i’m having:


The door’s orientation is closing correctly, but the position don’t.
How would i fix this bug?

My script:

local ProxPart = script.Parent
local Prox = ProxPart.ProximityPrompt
local TS = game:GetService("TweenService")
local Door = ProxPart.Parent.Door
local DoorCFrame = Door.CFrame
local Hinge = ProxPart.Parent.Hinge
local FixPowerGui = ProxPart.Parent.FixPowerGui
local TweenCFrame = Hinge.CFrame * CFrame.Angles(0, math.rad(120), 0)
local TweenCFrame2 = Hinge.CFrame * CFrame.Angles(0, 0, 0)
local DoorTween = TS:Create(Door, TweenInfo.new(0.6, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut), {CFrame = TweenCFrame})
local DoorTween2 = TS:Create(Door, TweenInfo.new(0.6, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut), {CFrame = TweenCFrame2})
local DB = false
local OpenSound = ProxPart.Open

Prox.Triggered:Connect(function(player)
	if DB == false then
		DoorTween:Play()
		FixPowerGui.Enabled = true
		OpenSound:Play()
		FixPowerGui.FixPower.MouseButton1Up:Connect(function()
			DoorTween2:Play()
			DB = true
			OpenSound:Play()
		end)
	end
end)

Any help would be appreciated :slight_smile:

1 Like

The issue is that you’re using the hinge CFrame for the TweenCFrame2 just use the Door.CFrame in that one so It goes to the original position and orientation

2 Likes

I think you need to set DB = true outside of the function

	if DB == false then
		DoorTween:Play()
		FixPowerGui.Enabled = true
		OpenSound:Play()
		FixPowerGui.FixPower.MouseButton1Up:Connect(function()
			DoorTween2:Play()
			OpenSound:Play()
		end)
        DB = true
	end
end)
2 Likes

Thanks, but that’s not what i meant. I already fixed it.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.