This isn’t a question so much as it is a request for advice from more experienced Roblox developers. Recently, I’ve been wondering about module scripts, and how to connect them to a model in 3D space. For example: If I wanted to have, say a bunch of items in a supermarket, each with prices and healthiness attributes stored in a module script, what is the best way to access that information from another script? Should I set up a function that scans through an array with all of the supermarket items to see which one’s model matches that of the target model? My wording is pretty bad, so let me summarize what I meant. I want to have an object that has properties stored in a module script. The question is, how do I access the module script’s properties from another script.
If you read this, then thank you. All responses are appreciated!
You will need to be more specific to help you in a better way, but you can just create functions to add, remove, change, get, etc… information about your items. Here’s an example of how I would organize this type of information, you can also use metatables to access information easier.
-- module
local Data = { }
function Data.new(properties: {[any]: any})
local ProductKey = properties.Key
Data[ProductKey] = {
Name = properties.Name;
Price = properties.Price;
Color = properties.Color
-- etc
}
return Data[ProductKey]
end
function Data.get(key: any)
return Data[key]
end
return Data
-- script
local module = require("Path to module")
module.new({
Key = "Key";
Name = "foobar";
Color = Color3.fromRGB(0, 0, 0)
})
print(module.get("Key").Name) -- foobar