Class metatable index is acting very weird

Because the value variable is a property of the TestTable, It just makes things more readable I guess, Here is a better example:

local Car = {}

Car.Name = "Lamborghini"
Car.Speed = 50
Car.Passenger = game.Players.zeyan200_gotdeleted

function Car:Activate()
	-- Code that activates the car.
end

function Car:ToggleLights()
	-- Code that toggles the lights of the car on and off.
end

function Car:Boost()
	-- Code that gives the car a speed boost.
end

If we just did:

local Name = "Lamborghini"
local Speed = 50
local Passenger = game.Players.zeyan200_gotdeleted

It wouldnā€™t really make much sense because the speed variable is for this specific car,
Sorry I am not the best at explaining, I am still new to classes too.

1 Like

self is a variable used in OOP and OOP related programming to refer to the object you are currently using, since in OOP everything related to the object is in the object. You can refer to the post I made linking someone elseā€™s explanation of it.

2 Likes

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