Is there any way to modify what the module will return in Lua?

Asked

Viewed 51 times

1

I want to know if it exists since I have a data storage system, in which the data stays in a table and when the player enters,this data is stored in a module script (The only one that returns something). The problem is that you can’t keep writing for example:

inventory=require(inventory)
inventory.Knifes=async.Knifes
inventory.ChosenKnife=async.ChosenKnife
inventory.Citrines=async.Citrines
--...

I’ve already tried

require(inventory)=async

but gave error. Appeared "Expected Dentifier,got ="

Please help me, I have little time!

Here’s the block I’m working on:

dss=game:GetService('DataStoreService'):GetDataStore('GameStuff')

game.Players.PlayerAdded:connect(function(player)
    local key='id='..player.userId
    local async=dss:GetAsync(key)
    if not async then
        local save={Knifes={1},ChosenKnife=1,Citrines=,Coins=0}
        dss:SetAsync(key,save)
        async=dss:GetAsync(key)
    end
    local module=script.ModuleScript:Clone()
    module.Parent=player:WaitForChild'PlayerGui'
    --Modificar o valor retornado de module
end
  • It’s not enough to do inventory=async?

  • I don’t know, I don’t think so, because before using require,Inventory is a cloned module in the Playergui folder, inside the player object. You can’t test it now because I’m away from home. If you want to test it for yourself, I’m using it. ROBLOX Studio

1 answer

1

I think it would be easier to adapt a class to your Inventory module. Otherwise, it seems that it is only possible to update the value of a module in versions of the Moon larger than 5.0, accessing the table package.loaded, in which its required module would be the field 'inventory', for example:

package.loaded.inventory = async

Perhaps it is unnecessary the Inventory module, if inventory == async (package.loaded.inventory will point to the same table of async, as in your last example as corrected above).

Browser other questions tagged

You are not signed in. Login or sign up in order to post.