So this issue has been bugging me for a while now, in scripts I normally pass over plr parameter to the module script so that I could use it later on while working around with UIs
Problem here is that if I pass it once it does what I want but if I’m doing this with multiple player it overwrites the value to the last plr that has used the function.
Is there a way to assign plr to you only without it getting overwritten, I want to do this on server than locally
Example:
function SideMenu.new(plr)
local Menu = {}
setmetatable(Menu)
SideMenu.plr = plr -- Becomes the plr instance
return Menu
end
local Menu = require(SideMenu)
Menu.new(plr)
Then it’s probably something wrong with your implementation of OOP, could it be that you also forgot to correctly set a metatable to Menu in your original code?
local SideMenu = {}
SideMenu.__index = SideMenu
function SideMenu.new(plr)
local Menu = {}
setmetatable(Menu, SideMenu)
SideMenu.plr = plr
return Menu
end
SideMenu has nothing inside of the plr key, to properly do it, try something like this where you required SideMenu
local menu = Menu.new(plr)
menu:PrintPlayer()
Although I’m not sure if this is exactly what you wanted in the end, if you need the plr objects to be in SideMenu, then you need to use a table and just add the player in that table