Need help for animated gate

Hello!
I want a cframed door/animated door but I dont know how to do this.
I have tried to make one but it was a failure.

I want my animated door to do this:

I have tried this script to open the door already:

Also I want a the red button to close the animated door.

1 Like

You could use TweenService. It would be a lot simpler. You could also optimize this by using loops.

for i = 0, 10, 1 do
     -- CFrame stuff here
     wait(0.1)
end

Well the problem is if I use my Cframed stuff it all goes wrong

I am bad at math so I am bad at CFrame

Try replacing the CFrame.fromEulerAnglesXYZ() with CFrame.Angles(0, 0.1, 0) I dont know math either so this might not work lol

Anyways I will try. This actually needs to be done today.

Nevermind. I just looked and that function is the same as Angles. Could you show a video of what exactly is happening each time you do anything with CFrames? Also show an image of what it looks like when correctly aligned?

Wait do you want it to be like opening a door towards yourself?

Sort of like this:

download

Yes like that or else I want the gate to go like inside the walls like this ← →

You can use tweenService and set a primaryPart for the model doors and record the positions!

Ok. For the gate going into the wall try changing your x coord to -0.35 (dont know if this will work).
For the other way Roblox has a dev hub post on CFrame math. They show you how to do this if you scroll down.

This is how I scripted my doors. Mess around with the code and u might get there.
robloxapp-20200510-1145417.wmv (3.8 MB) The second door is an example how can u play with it.

local Panel = game.Workspace.RDoor
local Part1 = Panel.PrimaryPart

for _, Part0 in pairs(Panel:GetChildren()) do
	if Part0:IsA("BasePart") and not (Part0 == Part1) then
		local WeldConstraint = Instance.new("WeldConstraint")
		WeldConstraint.Part0 = Part0
		WeldConstraint.Part1 = Part1
		WeldConstraint.Parent = WeldConstraint.Part0
		
		Part0.Anchored = false
	end
end

Part1.Anchored = true
Part1.CanCollide = false
----------------------------------------------------------------------
local Panel2 = game.Workspace.LDoor
local part2 = Panel2.PrimaryPart

for _, Part0 in pairs(Panel2:GetChildren()) do
	if Part0:IsA("BasePart") and not (Part0 == part2) then
		local WeldConstraint = Instance.new("WeldConstraint")
		WeldConstraint.Part0 = Part0
		WeldConstraint.Part1 = part2
		WeldConstraint.Parent = WeldConstraint.Part0
		
		Part0.Anchored = false
	end
end

part2.Anchored = true
part2.CanCollide = false
-----------------------------------------------------------------------
local tweenService = game:GetService("TweenService")
local mover = part2
local tweenInfo = TweenInfo.new(1)
local goals1 = {CFrame = mover.CFrame * CFrame.new(mover.Size.X - 0.2, 0, 0)}
local back1 = {CFrame = mover.CFrame}
local tween1 = tweenService:Create(mover, tweenInfo, goals1)
local tweenBack = tweenService:Create(mover, tweenInfo, back1)

local mover2 = Part1
local goals2 = {CFrame = mover2.CFrame * CFrame.new(-mover2.Size.X + 0.2, 0, 0)}
local back2 = {CFrame = mover2.CFrame}
local tween2 = tweenService:Create(mover2, tweenInfo, goals2)
local tweenBack2 = tweenService:Create(mover2, tweenInfo, back2)
----------------------------------------------------------------------------
local regionPart = game.Workspace.regionPart
local pos1 = regionPart.Position - (regionPart.Size / 2)
local pos2 = regionPart.Position + (regionPart.Size / 2)
local region = Region3.new(pos1, pos2)

local debounce = false
regionPart.Touched:Connect(function(hit)
	print("hi there")
	if debounce == false then
		debounce = true
		tween2:Play()
		tween1:Play()
	end
end)


local function tweenCompleted()
	local truth = false
	local db = true
	while debounce == true and db == true do
		wait(1)
		local partsInRegion = game.Workspace:FindPartsInRegion3(region, regionPart, 1000)
		for i, v in pairs(partsInRegion) do
			if v then
				if v.Parent:FindFirstChild("Humanoid") then
					debounce = true
					truth = true
					break
				else
					truth = false
				end
			end
		end	
		if truth == false then
			db = false
			tweenBack2:Play()
			tweenBack:Play()
		end	
	end
end

tweenBack2.Completed:Connect(function()
	debounce = false
end)

tween2.Completed:Connect(tweenCompleted)

also make sure there is no welds in the doors parts.