How do I fix this from happening

When ever I go to test my game with the doors I made the doors are supposed to be automatic Sliding doors but do this.
I want to achieve is to fix the doors from doing this
robloxapp-20201023-1224431.wmv (2.0 MB)

2 Likes

Iā€™m guessing you are CFraming the doors?
You may want to look at making the script work from the doorā€™s original Position since it appears youā€™ve got them in the first position, then you CFrame them to another position, then ā€˜slideā€™ them, and then ā€˜slideā€™ them back.
Try posting your script, but remember to put three backwards single quotation marks before and after the script. Ex: ```your script` `` (but donā€™t put the extra space in between them)

Here is the code sorry I took to long.

local door1 = script.Parent:WaitForChild("Door1")
local door2 = script.Parent:WaitForChild("Door2")
local tweeningInformation = TweenInfo.new(
	0.5,    
	Enum.EasingStyle.Linear,
	Enum.EasingDirection.Out,
	0,
	false,
	0
)
local door1Open = {CFrame = CFrame.new(-4.23, 3.99, -8.56)}
local door2Open = {CFrame = CFrame.new(-26.57, 3.99, -8.56)}
local door1Close = {CFrame = CFrame.new(-11.57, 3.99, -8.56)}
local door2Close = {CFrame = CFrame.new(-18.91, 3.99, -8.56)}
local tween1open = TweenService:Create(door1,tweeningInformation,door1Open)
local tween1close = TweenService:Create(door1,tweeningInformation,door1Close)
local tween2open = TweenService:Create(door2,tweeningInformation,door2Open)
local tween2close = TweenService:Create(door2,tweeningInformation,door2Close)

script.Parent.Detector1.Touched:Connect(function(hit)
	tween1open:Play()
	tween2open:Play()
	wait(2)
	tween1close:Play()
	tween2close:Play()
end)
script.Parent.Detector2.Touched:Connect(function(hit)
	tween1open:Play()
	tween2open:Play()
	wait(2)
	tween1close:Play()
	tween2close:Play()
end)```

What are the Positions of door1 & door2 in Studio before you run the script?
It appears you are CFraming them from one hard coded Position to another, but if the doors donā€™t start at that Position you are forcing them there when they first open.

Also, why not have 1 detector under both doors just above floor level, the size of both Detector1 and Detector2 since they both do the exact same thing?

Here is the file for the door to see what I did wrong.
Sliding Door 1.rbxm (4.0 KB)

Not currently on home computer so canā€™t open Roblox files.
Is the Position of door1 in Studio (-11.57, 3.99, -8.56)?
Itā€™s not a good idea to hard code the Positions of the CFrames. If you ever plan on moving or rotating the doors or wall then Iā€™d suggest you take the doorā€™s positions and add or subtract to their CFrames along the axis you plan on moving them.

I really donā€™t understand CFrames thatā€™s why its like that

All I need to know is when you are in Studio what is the Position of door1?

Your CFrame co-ordinates are indeed off.

Closing and Opening is actually quite simple to figure out co-ordinates for. We know that the position of your doors when closed is always equal to its neutral position. That is how itā€™s right now.

--- These should be your closed co-ordinates. 
local door1CloseP = door1.Position --   -8.036, 4.39, -0.93
local door2CloseP = door2.Position --   -15.286, 4.39, -0.93

As to figure out the opening co-ordinates, you can do a bit of trial and error and move the doors on the X axis in Studio. This way you can figure out the perfect position for it tween to when opened.

-- Variables for the opening position --
local door1OpenX = Vector3.new(0.8, 4.39, -0.93)
local door2OpenX = Vector3.new(-23, 4.39, -0.93)
-- Notice how only the X axis is being changed --

And finally, plugging these variables in to your tween to save hassle.

local door1Open = {CFrame = CFrame.new(door1OpenX)}  -- Opening position 
local door2Open = {CFrame = CFrame.new(door2OpenX)}  -- Opening position 
local door1Close = {CFrame = CFrame.new(door1CloseX)}  -- Neutral position
local door2Close = {CFrame = CFrame.new(door2CloseX)}  -- Neutral position 

Alternatively, you can create two parts to indicate where the open tween should go to, and grab its position and plug it in.

So with a bit of debugging, trial and error and moving the parts on the predominant axis we can tween our doors!

1 Like

Iā€™d imagine you want this to be answered in #help-and-feedback:scripting-support, as this can possibly involve CFraming, tweening and other coding related properties.

2 Likes

Am I replacing the hole script or parts of it?

I am having the lines when I put the script.

That means you havenā€™t stated the variables underlined, like you did with these lines in your original script:
local door1 = script.Parent:WaitForChild(ā€œDoor1ā€)
local door2 = script.Parent:WaitForChild(ā€œDoor2ā€)

Also you stated the variables door1closeP and door2closeP instead of door1closeX and door2closeX at the top of the script.