Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Way to store a table as a value?

1 answer

✓ Accepted answer

You can not store a table as a value but what you can do is save it to a DataStore using the DataStoreService and you need to make sure that you Enable Studio Access To API Services in the game settings or in the game configure page in the roblox website, Here is a simple example:

local exampletable = {"Trading_Opportunity","user2","user3"} -- The example table
local datastoreservice = game:GetService("DataStoreService") -- Gets data store service
local datastore = datastoreservice:GetDataStore("name") -- Gets a datastore, you can replace "name" with anything you want

pcall(function() -- Use this so it doesn't break the whole script if there is an error
datastore:SetAsync("name",exampletable) -- Make sure the first argument is the name of your data store and the second argument is the table
end)

When you want to get the table you create a variable and you set the variable to datastore:GetAsync("name") then you can use it to do whatever you want here is an example:

local tablee -- Creates a variable
pcall(function() -- Use this so it doesn't break the whole script if there is an error
tablee = datastore:GetAsync("name") -- Sets the variable "tablee" to the table saved to the data store
end)

-- Below is only an example, You can do anything you want with the table

game.Players.PlayerAdded:Connect(function(plr) -- When a player joined then connect function with the argument plr
for i=1, #tablee do -- Loop through the table
if plr.Name == tablee[i] then -- If the player's name is equal to anything in the table then
plr:Kick("eg") -- Player gets kicked for "eg"
end
end)
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.