If i create a OOP object by calling its .new function how can i access it in a different script?
Could try setting the value of an ObjectValue to the object, then calling that value from the 2nd script
You could also try bindable events, possibly
You could create a table that holds all created objects. When you call Class.new()
, add the created object to the object table. Then make some getter method to get that table of all objects
Example:
local Class = {}
Class.__index = Class
local AllObjects = {}
function Class.new(Name)
local Object = setmetatable({
Name = Name
}, Class)
table.insert(AllObjects, Object)
return Object
end
function Class:GetAllObjects()
return AllObjects
end
Class.new("a")
Class.new("b")
Class.new("c")
return Class
Then in another script
local AllObjects = Class:GetAllObjects()
for i, Object in ipairs(AllObjects) do
if Object.Name == "a" then
print'found'
end
end