Hi guys!
I’ve been struggling with something…
So I got this;
This is a module that handles all basically.
Now… this;
local tmp = require(script.profile)
local module = {}
module.__index = module
function module.getplayer(plr)
return module[plr] or module.new(plr)
end
As you can see, when module.getplayer(plr) get’s called, it returns the metatable stored if its found or, a new one.
Here is .new function()
function module.new(plr)
assert(plr ~= nil,"plr's nil.")
local self = setmetatable(tmp,module)
self.Player = plr
module[plr] = self
return self
end
So you wonder… uh, what’s trouble?
this;
local last = nil
for i,Player in pairs(game.Players:GetPlayers()) do
local fk = PlayersHandler.getplayer(Player)
print(last and last == fk or '')
last = fk
end
Both print the same, like if they were equals… I’ve tried this on ‘test’ (player 1,player 2) and doesn’t works with 2 players in-game aswell.
I really don’t know why they’re both equal, (they’re also returning same values!) no clue why…
When I do print(fk.InRace) they both Return ‘true’ if for example only 1 has it to true… this is really weird, I know.
Think it of as _G.InRace = true
like if fk was _G (it’s not obviously!)
Maybe it’s because tmp isn’t being required for each player? So when you do self.Player = plr it’s overwriting previous values. In other words setmetatable(tmp,module) isn’t returning a new table its just always returning the “original” tmp.