#metatables methods question

5 messages · Page 1 of 1 (latest)

whole ruin
#

so i have a table called Items containg all the players' items, when a player joins, i make a table for him and set Items as its table, then, i have a function for making items where it inserts the model inside the player's table inside Items and assignings to it Items's functions but when i try calling a function to the model it doesnt work

local Items = {}
Items.__index = Items

game.Players.PlayerAdded:Connect(function()
        Items[Player.Name] = {}
    setmetatable(Items[Player.Name], Items)
end)

function Items:sayname()
 print(self.Name)
end

function Items.MakeItem(name, owner)
  local model = script[name]:Clone()
  table.insert(Items[owner.Name], model)
  setmetatable(Items, {__index = model})

  model:sayname() --doesnt work

--*this is an example, not the actual script
end
whole ruin
#

so the problem is with setmetatable(Items, {__index = model} even tho i use it for making custom methods for objects with modules and it works fine

#

ok it was pretty simple

#

i only had to return setmetatable(Items, {__index = model}