How to get updated values which is from module script to local script?

Hello I’m doing something with module scripts,but I don’t understand on how to get module script functions which is stored in a table from local script,May anyone help,any help is appreciated,thanks!

What I really mean is for example,If I return a table from a module (using it as database at this point) and get a function which is in the table,but It doesn’t appear in local scripts whenever I print the table.

Ensure your functions are apart of the table that the module script returns.
I.e

-- Module script
local myModule = {}

myModule.someFunction = function()
    print("Hello from module!")
end

return myModule
-- Localscript
local module = require(path/to/module)

module.someFunction() --> Hello from module!
1 Like

Ah,I forgot to say something,sorry but I’m also updating the data of the module script as I mentioned it above,using it as database,so what I really need is how can I recieve updated data of module script from a local script,I’m using remote events but It seems to not show newest updated values.

I’m updating the data from a server side script and what I do is place the updated data to module script again and send a remote event to client for the client to get newest data

Changes you make to the module script won’t replicate, and you can’t send functions over the remote.

The best you can do is have all functions written out already, and only send the new table of data to the clients through the remote event.

1 Like

Thank you,I think there isn’t any other way to get functions through remote?

You can’t send a function through the remote. Roblox doesn’t allow that.

What’s your situation? Can the function not already be written on the client’s end?

Alright what I really mean is,If I can’t return function through remote events or remote functions (I assume It doesn’t work with remote functions too),Is there anyway like getting newest module script values and returning them to local script?

What’s my situation really is,I have a lots of data in a table (I have functions in it too) and I update it through a module function which is called “Update” . It basically Updates the data holder and then I need to get the newest Updated Data Holder to Local Script.

As far as getting the new data goes, you can do the following:

local myDataBase = {}
myDataBase.data = {...} -- This is the data WITHOUT functions

-- Your functions have to be pre-written somewhere. You can't send them through any remote
myDataBase.someFunction = ...


-- To update your data, listen to a remote event that sends the new data from the server.
myRemote.OnClientEvent:Connect(function(newData)
    myDataBase.data = newData
end)
return myDataBase

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.