Self is returning nil

and also this method is not fixing anything

No idea what that means, the line of code I provided above does not do that.

There is a : in the function definition, lua will automatically store whichever thing is calling the function as self in the function’s local scope, even if it’s called with the dot syntax, self will automatically become the first parameter it is passed. The only situation where self could be nil, is a function called with dot syntax with no parameters.

Hey mb, but I have never seen this syntax before. Could you please explain what you are trying to do?

i thought you were talking about creating the function and using self in place of the table like this
image

i miss understoof i alr replied saying mb

1 Like

im trying to get from self a value of payday and cooldown value, to test, if will give me money or coins after 15 seconds.

Where is this line of code?

Is it part of the module script?

uohiuhuhiuhuhiuhiuhiuhiuhiuhuhiu

okay, i will paste my new edited modulescript:

local EE = {}
local MT = {}
MT.__index = MT


function EE._Start()
	local self = setmetatable({},MT)
	
	self.Payday = 250 :: number
	self.CooldownPayday = 15 :: number
	
	return self
end

function MT:_InitRun()
	MT:_CreateLeaderstats(game.Players.LocalPlayer)
end

function MT:_CreateLeaderstats(player : Player)
	local Leaderstats = Instance.new("Folder")
	Leaderstats.Name = "leaderstats"
	Leaderstats.Parent = player
	
	MT:_CreateCoin("Money",player,Leaderstats)
end

function MT:_CreateCoin(NameOfCoin : string, player : Player, leaderstats : Folder)
	local Coin = Instance.new("IntValue")
	Coin.Name = NameOfCoin
	Coin.Value = 0
	Coin.Parent = leaderstats
	
	MT._EnablePayday(self, true, Coin)
end

function MT._EnablePayday(self : typeof(EE._Start()), Enable, Coin)
	if Enable then
		while true do
			print(self.Payday)
			Coin.Value += self.Payday 
			task.wait(self.CooldownPayday)
		end
	else
		warn("Payday is disabled")
	end
end

return EE

yes, at the beginning of modulescript i add a description and a instruction of using my modulescript

That line makes absolutely no sense, from what I can tell EasyEconomy is a module script in replicated storage, but you did not even require() it. Also please explain what :59: means

  1. I reqiure this module in localscript in StarterPlayerScripts
  2. In 59 line of code i tried print payday value, to see if this will get a nil or a number value.

Ohhhh, okay, I didn’t realize it was an error message.

Can I see the print then? also lmk where in the module you place it

I place module in replicatedstorage

I meant to ask, where in the module script are you printing this value? The code you provided is only 48 lines long…

if you ask the print line, well i show where is it

Im not exactly sure how to describe it but self is MT there is no payday value, this is because you called MT:_EnablePayday()
which makes MT self. If anyone else can explain better the call is in _CreateCoin

okay…

i will recode this module without a double table, i use this method of OOP from CrusherFire video( Object-Oriented Programming in Roblox Studio! (youtube.com)). And i learn what OOP is this. So i writing my framework in OOP.

So i will say sorry if i take your time into to empty. So can you send me a good and understood video about OOP in roblox studio.

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