I will try that and update here, thanks!
I just took another look at your script and noticed, you are overwriting the previous “Lobbies” table.
It worked but I’m not sure why I have to use self as the argument though. I can’t pass it as an argument from the script either, it just says ‘unknown symbol’.
If you’re gonna be indexing Lobbies/Lobby1 from inside a function inside of Lobbies, this will not work as it hasn’t been declared at the time of the function being made, so using self
allows us to access Lobby1 from inside the function of Lobby1.
Ended up returning to it now, doing print(self)
printed nil.
How are you calling it? You may have messed up a bit lol
Now it’s returning an actual error.
Table:
local Lobbies = {
['Lobby1'] = {
['HasStarted'] = false,
['MaxPlayers'] = 2,
['Players'] = {},
['Function'] = function(self)
print('Lobby1')
print(self)
end
},
['Lobby2'] = {
['HasStarted'] = false,
['MaxPlayers'] = 3,
['Players'] = {},
['Function'] = function(self)
print('Lobby2')
print(self)
end
},
['Lobby3'] = {
['HasStarted'] = false,
['MaxPlayers'] = 5,
['Players'] = {},
['Function'] = function(self)
print('Lobby3')
print(self)
end
},
['Lobby4'] = {
['HasStarted'] = false,
['MaxPlayers'] = 8,
['Players'] = {},
['Function'] = function(self)
for i,v in pairs(self['Lobby4']['Players']) do
print(v)
end
end
}
}
Later in the script, where the error says it’s happening
coroutine.wrap(Lobbies['Lobby'..lobby]['Function'])()
Error: ServerScriptService.LobbyHandler:75: ServerScriptService.LobbyHandler:34: attempt to index nil with 'Lobby4'
Should mention that I tried Lobby4 and that’s why no other functions have the timer, it should be being called though.
Remember to pass in the Lobby table when calling the thread
local LobbyTable = Lobbies['Lobby'..lobby]
coroutine.wrap(LobbyTable['Function'])(LobbyTable)
-- Cause self is the Lobby table.
Ohhh, I see. So you have to tell the table that it is itself if that makes sense?
Lol, yeah.
It’s kind of like this
in a couple of Object-Oriented programming languages – and self is used heavily in OOP in Roblox