Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Sliding Door won't work. CFrame (Position + Vector3) not moving?

I have a grouped everything together. I also referenced this video: https://www.youtube.com/watch?v=ZnBz_kbSnm8&index=45&list=WL&t=1115s

-Automatic Door, Script, -Door1, Frame, Frame, Frame, Frame, Glass, -Door2, Frame, Frame, Frame, Frame, Glass, Frame (x11), Glass (x3), Sensor,

Script:

door1 = script.Parent.Door1
door2 = script.Parent.Door2

doorClosed = true

script.Parent.Sensor.Touched:connect(function(hit)
	local h = hit.Parent:FindFirstChild("Humanoid")
	if h then
		if doorClosed then
			doorClosed = false
			for i = 1,30.3 do
				door1.CFrame = CFrame.new(door1.Position + Vector3.new(0,0,0.3))
				door2.CFrame = CFrame.new(door2.Position + Vector3.new(0,0,-0.3))
				wait()
			end
			wait(0.3)
			for i = 1,30.3 do
				door1.CFrame = CFrame.new(door1.Position + Vector3.new(0,0,-0.3))
				door2.CFrame = CFrame.new(door2.Position + Vector3.new(0,0,0.3))
				wait()
			end
			doorClosed = true
		end
	end
end)

Please help me, thank you.

2 comments

1

Is there any output? Have you added print()s to make sure the loops are starting at all?

0

I have no clue what an output is. And I did not add print().

1 answer

First off, output is the information that the program processes and sends out. Print() is the easiest and simplest output function.

The easiest way to make a sliding door is not with CFrame, but with a PrismaticConstraint. Simply attach one attachment to the door, and one to the wall it is sliding from, and put a PrismaticConstraint in between. Then, change the ActuatorType to Servo, mess around with the settings a bit until you get what you like, change the TargetPosition to 0, and put the following code in your script:

door1 = script.Parent.Door1
prismatic1 = door1.PrismaticConstraint
door2 = script.Parent.Door2
prismatic2 = door2.PrismaticConstraint
--Assuming that you already have the PrismaticConstraints installed correctly, that is...

doorClosed = true

script.Parent.Sensor.Touched:connect(function(hit)
	local h = hit.Parent:FindFirstChild("Humanoid")
	if h and doorClosed then
        	doorClosed = false
		prismatic1.TargetPosition = 45 --or whatever you want
		prismatic2.TargetPosition = 45
		wait() --however long it takes for your doors to open
		prismatic1.TargetPosition = 0
		prismatic2.TargetPosition = 0
		wait() --the same amount of time
		doorClosed = true
	end
end)

See how much cleaner that looks using a Constraint instead of a CFrame?

This discussion is preserved as it was. New answers, comments, and votes are closed.