Hello, I would like know how to create table values. Can you help me please?
I highly suggest to look it up at the API Reference here and looking at other topics before posting before posting to the developer forums.
You can just do ArrayName[n] = Value where ArrayName is the table’s name (they are the same thing).
I would like get value in intances. no values in a script.
I’m confused on what you’re asking, but you can do
local children = <Instance>:GetChildren() -- get's the children of the given instance
or
local name = <Instance>.Name
print(name) -- prints the name of whatever instance you used
I have another question. It is possible to set table async to save data values or I must use the httpService to convert it to string?
It’s possible to save the content of a table into a data store, it’s not that hard to do. if you mean that?
local mainDataStore = game:GetService("DataStoreService")
local myTable = {} -- The table you'd like to save
game.Players.PlayerAdded:Connect(function(player)
local tableData -- Save the data on this variable
local success, unsuccesful = pcall(function()
tableData = mainDataStore:GetAsync(player.UserId) -- Get the data and store it temp on a variable
end)
-- Get the data and store it to the table
if tableData ~= nil then -- Examine if there is any data on the variable
for _, dataItem in pairs(tableData) do
table.insert(myTable, dataItem) -- Store the data on the table
end
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local success, unsuccesful = pcall(function()
mainDataStore:SetAsync(player.UserId, myTable) -- Save the table
end)
end)
-- If the game suddenly shuts down
game:BindToClose(function()
-- Get all the players
for _, player in pairs(game.Players:GetPlayers()) do
local success, unsuccesful = pcall(function()
mainDataStore:SetAsync(player.UserId, myTable) -- Save the table
end)
end
end)
Edit: I didn’t have time to test it yet so there may be bugs
1 Like