Reputation: 24628
I don't seem to be able to add textual data (e.g. in CSV, JSON or XML files) to the Roblox DataModel
, Workspace
, ServerStorage
or anywhere really?
Any hints on how to do this efficiently? Ideally, Roblox should just give me the contents of the file as a table. But if there is a way to get a raw string from a file that I have to parse manually, I could cope, too.
Upvotes: 3
Views: 1994
Reputation: 1376
As already said you cannot add "files" to the DataModel. However you can use the HttpService to load the data from a webserver (also decode and encode JSON). If you do not want to load it that way, you can use a Script or ModuleScript to store data.
To make it easy, you can use multiline strings (make sure to read about the "Nesting quotes") like so:
local data = [[Here is your
data that can
span over multiple lines,
so just copy-paste the content]]
print("My data: " .. data)
With ModuleScript:
return [[Here is your
data that can
span over multiple lines,
so just copy-paste the content]]
Usage of ModuleScript:
local data = require(game.ServerStorage.your.module.script.text.file)
print("My data: " .. data)
And if you want a JSON text to be decoded into a table:
local data = game:GetService("HttpService"):JSONDecode(require(game.ServerStorage.your.module.script.text.file))
Or in a ModuleScript:
return game:GetService("HttpService"):JSONDecode([[Here is your
data that can
span over multiple lines,
so just copy-paste the content]])
You could also store the text in a StringValue
Upvotes: 3
Reputation: 107
If I recall correctly, Roblox only allows for their files(RBXM, RBLX, etc.) to be inserted into studio. If it's a text file you want, I recommend just creating a new script instance and then copying the text over to that script.
Upvotes: 0