Issue with OOP door

Hey so I am making a door using OOP. It has two doors.

My script doesn’t work as for my tween it is saying Argument 3 missing or nil.

local ts = game:GetService("TweenService")

local door = {}
door.__index = door

door.openTime = 0.2
door.closed = true

function door:New(model)
	local newDoor = setmetatable({}, self)
	newDoor.__index = newDoor
	newDoor.Model = model
	
	return newDoor
end

function door:CreateLeftTween(properties)
	local tween = ts:Create(
		self.Model.Door1.MainPart,
		TweenInfo.new(self.openTime, Enum.EasingStyle.Sine, Enum.EasingDirection.In),
		properties
	)
	
	return tween
end

function door:CreateRightTween(properties)
	local tween = ts:Create(
		self.Model.Door2.MainPart,
		TweenInfo.new(self.openTime, Enum.EasingStyle.Sine, Enum.EasingDirection.In),
		properties
	)

	return tween
end

function door:Toggle()
	self.closed = not self.closed
	
	local propertiesLeft = {}
	propertiesLeft[true] = {Position = self.Model.Door1.MainPart.Position + Vector3.new(0, 0, 3)}
	propertiesLeft[false] = {Position = self.Model.Door1.MainPart.Position}
	
	local propertiesRight = {}
	propertiesLeft[true] = {Position = self.Model.Door2.MainPart.Position - Vector3.new(0, 0, 3)}
	propertiesLeft[false] = {Position = self.Model.Door2.MainPart.Position}
	
	local tweenLeft = self:CreateLeftTween(propertiesLeft[self.closed])
	local tweenRight = self:CreateRightTween(propertiesRight[self.closed])
	tweenLeft:Play()
	tweenRight:Play()
end

return door

Odd thing is that it doesn’t say this error for the left door.

You forgot to change it to propertiesRight, you’re only changing the properties table for the left door, the right one receives no changes so it’s empty

local propertiesRight = {}
propertiesRight[true] = {Position = self.Model.Door2.MainPart.Position - Vector3.new(0, 0, 3)}
propertiesRight[false] = {Position = self.Model.Door2.MainPart.Position}
1 Like

Alright that seemed to work, but the doors don’t open.

Are you obtaining anymore errors?

Nope, no more errors in the console.

Here is my server script if you need it:

local small_door_mod = require(script.DoorSliding)

local cs = game:GetService("CollectionService")

local SMALL_DOOR_TAG = cs:GetTagged("SmallSliding")
local MEDIUM_LOCKDOWN_TAG = cs:GetTagged("MediumLockdown")
local LARGE_SLIDING_TAG = cs:GetTagged("LargeSliding")

for _, door in pairs(SMALL_DOOR_TAG) do
	local newDoor = small_door_mod:New(door)
	newDoor:Toggle()
	wait(4)
	newDoor:Toggle()
end

From what I can see, the first time it’ll be closed since closed is initalized as true, maybe that’s related?

I have accounted for that and it still doesn’t open.

Right, sorry about that, it’s late for me. I’m not sure if you did something wrong with the OOP stuff you have set up or something else is wrong, looking at the code doesn’t show an inherent issue, that or I’m probably inexperienced with OOP and can only really point the simple flaws. I think you may need to debug stuff around

Alright thanks anyways. gotta add more for char

1 Like