Help Fixing Automatic Door

Hi guys. I’m trying to make an automatic door. I tried to use two tweens (one for each door). It doesn’t work though.

Here’s the script I provided:

local Plr = game.Players.LocalPlayer -- That's you :)

local part1 = script.Parent.Sensor1 -- The sensor outside the building
local part2 = script.Parent.Sensor2 -- The sensor inside the building
local slidingdoor = script.Parent.SlidingDoor -- The sliding door with the tweening parts
local door1 = slidingdoor.Door1 -- The first door
local door2 = slidingdoor.Door2 -- The second door

local TwnS = game:GetService("TweenService") -- Assigning the main variable

local tweenInfo = TweenInfo.new() -- This is the speed of the tween
local Position1 = door1.RootPart.CFrame == CFrame.new(172.875, 6, 1004.375) -- Change this to the position you want door 1 to stop at.
local Position2 = door2.RootPart.CFrame == CFrame.new(185.625, 6, 1004.375) -- Change this to the position you want door 2 to stop at.

local Tween1 = TwnS:Create(door1.RootPart, tweenInfo, {door1.RootPart.CFrame*CFrame.new(door1.RootPart.Size.X + 875, 6, 1004.375)})
local Tween2 = TwnS:Create(door2.RootPart, tweenInfo, {door2.RootPart.CFrame*CFrame.new(door2.RootPart.Size.x + 625, 6, 1004.375)})

part1.Touched:Connect(function()
	local success, errormessage = pcall(function()
		Tween1:Play()
		Tween2:Play()		
		wait(10)
	end)
	
	if success then
		print("Successfully tweened!")
	else
		print("An error occurred while tweening. Please try again")
		warn(errormessage)
	end
end)

It still didn’t work without the protected call. If you have suggestions, don’t be shy. I’d be happy for you to find a way to fix this. Thx :slightly_smiling_face:

Inside the Tweens, the third argument must be a table, and inside of that table, the properties must be assigned like this :

{CFrame = ...., Color = ....}

In your case:

Change these lines :

local Tween1 = TwnS:Create(door1.RootPart, tweenInfo, {door1.RootPart.CFrame*CFrame.new(door1.RootPart.Size.X + 875, 6, 1004.375)})
local Tween2 = TwnS:Create(door2.RootPart, tweenInfo, {door2.RootPart.CFrame*CFrame.new(door2.RootPart.Size.x + 625, 6, 1004.375)}}

To:

local Tween1 = TwnS:Create(door1.RootPart, tweenInfo, {CFrame = door1.RootPart.CFrame*CFrame.new(door1.RootPart.Size.X + 875, 6, 1004.375)})
local Tween2 = TwnS:Create(door2.RootPart, tweenInfo, {CFrame = door2.RootPart.CFrame*CFrame.new(door2.RootPart.Size.x + 625, 6, 1004.375)})

The third argument inside the Tween , must be a table, a dictionary to be more accurate, and to assign properties, do like this -

{Color = ..... , Size = ..... }

Plus, if that script is a server script, you cant assign the local player like that.

1 Like

Should the coordinates in that argument be the target position?

I dont get this part, why create an instance and then define positions you never use again… read this doc on tweens:

https://developer.roblox.com/en-us/api-reference/function/TweenService/Create

And also @Valkyrop is right about calling local player.

1 Like

So I don’t need the local position1 and position2 sections?

I dont think so. Have you tried what I told you?

I did. Thanks for your help. :slight_smile: