How to get the table memory address in a script?

Hi, it’s me again! So I would like to get the memory address to get my table into another script without using the _G or shared variables. Unfortunately it’s hard to get it without the memory address of the targeted table. My idea would be to get the address and use my table in another script, because I save it as a string and reuse it later. One idea would be the function getmetatable() (yes, I work with metatables, so I prefer to use OOP), but with this function I only get the metatable and not the table itself. So is there a way to get the memory address of a table and get the table back later?

Thx for reading:
~~Eterna

Could look into module scripts. Return the table you want, then just require the module each time you need the table.

1 Like

So, ik that this is false, but it would nice if this was possible. And i am working with OOP, so i am using ModuleScripts, metatables and more. Its just annoying that i need to create more classes instead of always create new classes:

--Class
--I'm trying to create a capability class with functions, so I want to use the function of a capability instead of always creating a new class.
local LightSkill = {}

local AbstractSkill = require(AbstractSkillModule)

LightSkill.__index = LightSkill

function LightSkill.new(Level, Owner, Brightness)
    local NewSkill = AbsctractClass.new(Level, Owner)
    NewSkill.Brightness = Brightness
    setmetatable(NewSkill, LightSkill)
    return NewSkill
end

function LightSkill:Execute() --For this reason I want to use the same class in several scripts, so I can simply use this feature of my already created class. Then I want to make it so that I can improve my ability, so I don't want to use Skill1, Skill2, Skill3, ... classes, but only one class for several levels. Hope was clear enough
    --Do stuff
end
return LightSkill

--Script1
local Class = require(LightSkill)
local LightSkill = Class.new(nil, nil, nil) --just am setting nil as this is just a example
game.ReplicatedStorage.StringValue.Value = LightSkill:GetMemoryAddress() --So that i can use this between more scripts

--Script2
local Class = (game.ReplicatedStorage.StringValue.Value):ConvertToTable
Class:Execute() --Only 1 class, but this is shared by more scripts

Are you simply looking to share this across scripts? Just use more modules? I don’t know what to tell you. I don’t know why you want to tostring the table and get its memory address to dereference it from the other side.

1 Like

So how can I explain it, imagine that you produce a classe. This class then has data (strength of ability and more). But now if you create a new class again and again, the memory of the device will be full in a moment. This is why I want to avoid creating multiple classes. I know a lot about java, if you can understand better what I mean. In java such a thing would be possible:

//class
// Srry, i not really am good with java but you should understand
import AbstractSkill
public class Skill extends AbstractSkill{
    public static Name;
    public int Brightness;
    public PlayerClass Owner;
    public Skill(Name, Owner, Brightness) {
        super(Name, Owner)
        this.Brightness = Brightness;
    }
    @Override //Overriding the abstract Method
    public void execute() {
        //do stuff
    }
}

//Script1
import Skill
public class Script1{
    public Skill LightSkill = new Skill(null, null, null) //The class was now created
}

//Script2
import Script2
public class Script2{
    System.out.println(Script1.LightSkill.Name)
}

Yes, i not am really good in java, but as you can see, you can get a variable from a class/script and use it in another place/script. Do you now understand me @incapaz ?

You could just use a module for storage, you don’t need to make a whole class. Just do module.Table = myTable and check module.Table in the other script.