#self is set to the wrong table but if i use getmetatable() then it shows the correct table

18 messages · Page 1 of 1 (latest)

bright trout
#

this is my script

local Lib = {
  ServerDefault = {
    Tool = {
      _ = {};
      test = 1;
    }
  }
}
Lib.ServerDefault.Tool.__index = Lib.ServerDefault.Tool

local System = Lib.ServerDefault.Tool._
System.__index = Lib.ServerDefault.Tool
function System:hi() warn(self) print(getmetatable(self)) end
setmetatable(System, Lib.ServerDefault.Tool)

local Clone = table.clone(Lib.ServerDefault.Tool) Clone._:hi()
ancient vale
bright trout
#

System:hi() is supposed to warn Lib.ServerDefault.Tool but it doesnt

ancient vale
#

try this
System.hi = function() warn(self) print(getmetatable(self)) end

#

i dont think it will work but try it

#

@bright trout are you working on a game rn?

bright trout
#

yes

#

now i found other problem

ancient vale
#

k

#

i think i found the problem

#

its a cycle

ancient vale
#

its a cycle

bright trout
#

its what i always did for my modules

#

i have to go to stupid school now i cant give more code example

#
local gLib = game:WaitForChild("FURE"):Invoke()
local Lib = {
    Settings = {
        Debug = true,
        ConsolePrefix = "[FURE/Tools]: ",
    };
    
    Sounds = {};
    ToolLib = {};
    Tools = {};
    ServerDefault = {
        gLib = gLib,
        Tool = {
            Settings = {
                ToolName = nil; -- 'nil' means the name won't be changed on load
                MaxDistance = 10;
                MaxHits = 1;
                Damage = 10;
                Cooldown = .75;
                HoldActionDelay = 1.25;
                CastDelay = .25;
                CastTime = 1;
                SoundDelay = .25;
            };
            AllowedSettingsShare = {};
            Load = nil;
            Equipped = nil;
            Unequipped = nil;
            Activate = nil;
            Hitboxes = {};
        },
    };
}
Lib.ToolLib.__index = Lib.ToolLib
Lib.ServerDefault.Tool.__index = Lib.ServerDefault.Tool

function Lib.ServerDefault.Tool:StopCasts(Reason)
    for _, Hitbox in pairs(self.Hitboxes) do
        Hitbox:StopCast(Reason)
    end
end

local System = {}

function System:Activated()
    self:PlaySound("Use")
    --------------------------------------------------
    Bindables[self.Obj].Activated:Fire()
end

System.__index = Lib.ServerDefault.Tool
setmetatable(System, Lib.ServerDefault.Tool)
Lib.ServerDefault.Tool._ = System```
#

if i remove the cycle, then :stopcasts break
if i keep it, then lib.serverdefault.tool becomes lib.serverdefault.tool._ for some reason

#

there is a module for each one of the different tools and they need the bindable to add new functions apart from the default ones