This error keeps appearing in my door opening script

So, I’m trying to make an automatic door that opens when a player is touching it, I already scripted it using union parts in 2 different models, 2 models with one door part inside, the door will not rotate, just like automatic doors, They move backwards and then forwards.

Doors parts, one door is an union and the other is another union.

These are the doors I’m trying to make, they’re supposed to move like the image says.

This the script that haves an error in line 31.


local mainPart = workspace.LEFTDOOR.Union
local TService = game:GetService("TweenService")


local Door2 = workspace.rIGHTDOOR.Union


local success, newUnion = pcall(function()
	return mainPart:UnionAsync(mainPart, Door2)
end)


if success and newUnion then
	newUnion.Position = mainPart.Position
	newUnion.Parent = workspace
end




local doorModel = newUnion


local closedPosition = Vector3.new(mainPart.Position.X, mainPart.Position.Y, mainPart.Position.Z)


local openPosition = Vector3.new(mainPart.Position.X - mainPart.Size.X, mainPart.Position.Y, mainPart.Position.Z)


local tweenInfo = TweenInfo.new(1, "Quad", Enum.EasingDirection.In, 0, false, 0)


local tween


local function touched(part)
	if part:FindFirstChild("Humanoid") then

		tween = TService:Create(doorModel, tweenInfo, {Position = openPosition})
		tween:Play()
	end
end


doorModel.Touched:Connect(touched)


local function touchEnded(part)
	if part:FindFirstChild("Humanoid") then

		tween = TService:Create(doorModel, tweenInfo, {Position = closedPosition})
		tween:Play()
	end
end


doorModel.TouchEnded:Connect(touchEnded)

Thanks for helping!! If any confusions reply me

Here is a fully steamrolled untested guess, based off what you have now.

local mainPart = workspace.LEFTDOOR.Union
local TService = game:GetService("TweenService")
local Door2 = workspace.RIGHTDOOR.Union
local success, newUnion = pcall(function()
    return mainPart:UnionAsync(Door2)
end)
if success and newUnion then
    newUnion.Position = mainPart.Position
    newUnion.Parent = workspace
end
local doorModel = newUnion
local closedPosition = Vector3.new(mainPart.Position.X, mainPart.Position.Y, mainPart.Position.Z)
local openPosition = Vector3.new(mainPart.Position.X - mainPart.Size.X, mainPart.Position.Y, mainPart.Position.Z)
local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.In, 0, false, 0)
local tween
local function touched(part)
    if part:FindFirstChild("Humanoid") then
        tween = TService:Create(doorModel, tweenInfo, {Position = openPosition})
        tween:Play()
    end
end
doorModel.Touched:Connect(touched)
local function touchEnded(part)
    if part:FindFirstChild("Humanoid") then
        tween = TService:Create(doorModel, tweenInfo, {Position = closedPosition})
        tween:Play()
    end
end
doorModel.TouchEnded:Connect(touchEnded)

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