Self value in two cases

So I have a module script that uses self twice, however I didn’t make this script, I am copying it of a yt tutorial to help my OOP understanding.

So please tell me, logically, what self's value is in these two cases:

local ts = game:GetService("TweenService")
local door = {}
door.__index = door

door.Closed = false
door.CloseTime = 2

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

     return newDoor
end

function door:TweenDoor(properties)
     local tween = ts:Create(
     self.Model.Door, -- Here
     TweenInfo.new(
     self.CloseTime, -- And here
     Enum.EasingStyle.Quad, 
     Enum.EasingDirection.Out
     ),
     properties
end

In both cases whatever object those instance methods are being called on.

1 Like

Boom I’m back from learning OOP damn so powerful ty for using it.

Both or more self in a function will always be the same, since self is declared when the function itself was called.

(edited cuz there was self there)

Also, self value depends on the objects you used to call the function.
If you do

door:TweenDoor()

then self value would be door