Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Is there a way to store a table inside a player's folder?

Asked by 4 years ago
Edited 4 years ago

I basically have this script: is there a way i could have a table as a value? any way to do that?

01local function joined(player)
02    local leaderstats = Instance.new("Folder",player)
03    leaderstats.Name = 'table'
04 
05    local items = Instance.new("IntValue",leaderstats)
06    items.Name = "Items"
07    items.Value = t{'item1','item2','item6'}
08 
09end
10 
11game.Players.PlayerAdded:Connect(joined)

thanks for your time!

2 answers

Log in to vote
1
Answered by 4 years ago

Most scripters opt against storing values in instances: Storing values in the player: good or bad

Instead, values are contained within code keyed on the player's ID/Name:

Server Script

01--This is example code of a server script inside ServerScriptService
02 
03--Just initializing the userData at a high scope so all the functions can access it
04local userData = {}
05--Get the players service
06local players = game:GetService("Players")
07 
08--This function is ran only once for each player that joins the game
09local function joined(player)
10 
11    --Each player is given their own table/subTables
12    --Included the Coins key just as another example of defaulting the value
13    userData[player.Name] = {
14        ["Items"] = {};
15        ["Coins"] = 0
View all 42 lines...

You can then easily use userData to access any user data you've defined all from one place. You can even turn it into a module script and return specified values as-needed which are up-to-date. If the client needs the information, then simply send the information over using a remote. I hope this helps, I tried to be as informative as possible

0
Oh wow This is really helpful for me!!! Im going to use this method instead. Im also going to use it for DataStores! Thank you so much! Have a great day! Mast3rStRix 43 — 4y
1
Yeah data store methods are much better! :) You can make your own (there's a great tutorial in the guides section) or you can try DataStore2 which you can download/get from the workshop :) AlexTheCreator 461 — 4y
1
No problem at all! You're absolutely right to use this for DataStores since it's a partial example of caching the data. SteelMettle1 394 — 4y
Ad
Log in to vote
1
Answered by
marfit 104
4 years ago

No. In Roblox, putting a table into something like this only gives you "Table:" and then the table's memory address. You'd be better off dividing that "Table" section in your leaderstats into the three different sections and put each value into one.

You can also run this code and turn the table into a continuous string.

1local TableString = ""
2 
3for _,v in ipairs(Table) do
4    TableString = TableString..v.." "
5end
6 
7print(TableString)
0
Thanks ! Mast3rStRix 43 — 4y

Answer this question