I basically have this script: is there a way i could have a table as a value? any way to do that?
local function joined(player) local leaderstats = Instance.new("Folder",player) leaderstats.Name = 'table' local items = Instance.new("IntValue",leaderstats) items.Name = "Items" items.Value = t{'item1','item2','item6'} end game.Players.PlayerAdded:Connect(joined)
thanks for your time!
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
--This is example code of a server script inside ServerScriptService --Just initializing the userData at a high scope so all the functions can access it local userData = {} --Get the players service local players = game:GetService("Players") --This function is ran only once for each player that joins the game local function joined(player) --Each player is given their own table/subTables --Included the Coins key just as another example of defaulting the value userData[player.Name] = { ["Items"] = {}; ["Coins"] = 0 } --Just an example of how to access the table userData[player.Name].Items = {"item1", "item2", "item6"} userData[player.Name].Coins = 500 --[[The table now looks like this if you and I joined the game: userData = { ["Mast3rStRix"] = { ["Items"] = {"item1", "item2", "item6"}; ["Coins"] = 500 }; ["SteelMettle1"] = { ["Items"] = {"item1", "item2", "item6"}; ["Coins"] = 500 }; } ]] end --Only runs once when the player leaves the game players.PlayerRemoving:Connect(function(player) --Set the player's key to nil so we don't have any nasty memory leaks --Obviously don't do this until any data that needs to be saved is saved userData[player.Name] = nil end) --Hook the joinedfunction to the PlayerAdded event players.PlayerAdded:Connect(joined)
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
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.
local TableString = "" for _,v in ipairs(Table) do TableString = TableString..v.." " end print(TableString)