Hi there! I'm trying to mess around with different ways for storing data via DataStore without saving each value individually. Someone I know had suggested trying to save it all with a table, so I'm trying to do that. However, I'm a bit confused as to how I would use table.insert(), or anything else to add the name of the value, and the value itself to the table? Any help is greatly appreciated. :)
What I want:
local Table = { ["Cash"] = 0 }
Script I've tried using:
local Table = {} for _,v in pairs(Player["leaderstats"]:GetChildren()) do table.insert(Table, {[v.Name] = v.Value}) end
Its simple, dont need to use table.insert
you can only use Table[ITEM] = VALUE
This basically creates a new value in a table. because you're basically setting this for the table.
Here is a example:
local Table = {} Table["Coin"] = 120 -- Add the value to table. wait() print(Table["Coin"]) -- Print the value.
Here is your fixed script:
local Table = {} -- Items table for _,v in pairs(Player["leaderstats"]:GetChildren()) do -- Get all items in leaderstats in player Table[v.Name] = v.Value -- Add the values to table. end
Hope it helped :)