Confusion regarding B Ricey video

  1. What do you want to achieve?

I want to understand this video from B Ricey.

  1. What is the issue?

I don’t understand what this self is equivalent to. I understand that self can be a variable and that in a function with a colon it is equivalent to the table it is inside of but I don’t know if self is coming from the .new() function or it’s the entire Tycoon module.

Module
local template = game:GetService("ServerStorage").Template

local function newmodel(model, vector)
	local newModel = model:Clone()
	newModel.Parent = workspace
	newModel:MoveTo(vector)
	return newModel
end


local Tycoon = {}
Tycoon.__index = Tycoon

function Tycoon.new(player)
	local self = setmetatable({},Tycoon)
	self.Owner = player
	
	return self
end

function Tycoon:Init()
	self.Model = newmodel(template, Vector3.new(0,1,0))
end

function Tycoon:Destroy()
	self.Model:Destroy()
end

return Tycoon
Server
local Tycoon = require(script.Parent.Tycoon)

game:GetService("Players").PlayerAdded:Connect(function(player)
	local tycoon = Tycoon.new(player)
	tycoon:Init()
end)

My confusion is in the .new() and .Init() functions which both use self. In the server script you can see “tycoon:Init()”, does this make the self from .new() equal the self in .Init() or is the self in .Init() equal the parent table.

  1. What solutions have you tried so far?

I’ve tried using the AI assistant to break down and simplify the self keyword. I also watched B Ricey’s self keyword video. The main issue is very specific though.

https://www.youtube.com/watch?v=Gart69xNY-M&list=PLXSd5YZgxaXRMUSWybIRkELeIQLXJNZM7

All replies are appreciated.

1 Like
function Tycoon:Check()
	print(self)
end

Solution found, the self keyword did inherit the tycoon.new() table.

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