How would I approach this?

Hello, I have a rather simple(?) question, how would I implement this, I’ve tried it and I can’t seem to get it to work. This is basically what I wanted to do; I want to add the player into the playerlist, and have functions inside it so that I can basically run the functions from different scripts.

local playerlist = {
	player1 = {
		data = {
			save() -- pretend this is a function
			update()
		},
		weapon = {
			shoot()
			reload()
		},
	}
}

I do not have any idea on how would I approach this, should I just go and do it as: or is there a better option, if there, is how would I do it?

-- Method A

local playerlist = {
	player1 = {
		data = {
			save = function()
				
			end,
			
			update = function()
				
			end,
		},
		weapon = {
			shoot = function()
				
			end,
			
			reload = function()
				
			end,
		},
	}
	
}

Instead of having functions inside player data, have functions that interact with player data.

-- Your way:
player.save()
-- Good way (for your situation):
save(player)
1 Like