(Easy query) Issue with my automatic door script

I have made a simple automatic door using three parts previously and it has worked with a similar script, however, I altered it to fit a more detailed door model and for some reason, it has not worked.


In the video, the left door works perfectly and shows in the output that the player is detected. However, I ported the same script and altered it for the right door, which contains several meshparts rather than a single part for the doors. I have attached the script below can anyone help, please? Thank you!

Could I also have some tips regarding moving multiple parts in a model, as I do not understand how to utilise a primary part to do this?

local TweenService = game:GetService("TweenService")

local model = script.Parent
local leftDoor = model.LeftDoor.mainPart
local rightDoor = model.RightDoor.mainPart
local light = model.NeonPart
local collision = model.collisionBox

local openInfo = TweenInfo.new(
	1,
	Enum.EasingStyle.Linear,
	Enum.EasingDirection.Out,
	0,
	false,
	0
)

local closeInfo = TweenInfo.new(
	2,
	Enum.EasingStyle.Quart,
	Enum.EasingDirection.Out,
	0,
	false,
	0
)

local leftOpenPos = {}
local leftClosePos = {}
local offset = Vector3.new(-leftDoor.Size.X,0,0)
leftOpenPos.CFrame = leftDoor.CFrame * CFrame.new(offset)
leftClosePos.CFrame = leftDoor.CFrame

local leftOpen = TweenService:Create(leftDoor,openInfo,leftOpenPos)
local leftClose = TweenService:Create(leftDoor,closeInfo,leftClosePos)

local rightOpenPos = {}
local rightClosePos = {}
rightOpenPos.CFrame = rightDoor.CFrame * CFrame.new(rightDoor.Size.X,0,0)
rightClosePos.CFrame = rightDoor.CFrame

local rightOpen = TweenService:Create(rightDoor,openInfo,rightOpenPos)
local rightClose = TweenService:Create(rightDoor,closeInfo,rightClosePos)

local function Open()
	rightOpen:Play()
	leftOpen:Play()
	light.BrickColor = BrickColor.new("Lime green")
end
 
local function Close()
	rightClose:Play()
	leftClose:Play()
end

local opening = false

collision.Touched:Connect(function(hit)
	local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	if player then
		print("player detected!")
		opening = true
		Open()
	end
	opening = false
end)

collision.TouchEnded:Connect(function(hit)
	local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	if not player and opening == false then
		print("no player detected")
		Close()
	end
end)
1 Like

Considering you are tweening a model, do you have a primary part anchored with the rest being unanchored and connected with WeldConstraints?
It should look something like this.
ex

3 Likes

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