Hello, what i mean with the title is basically this:
local list {
waluigi = false;
wario = true;
luigi = false;
mario = false;
bowser = true;
}
And save that in a datastore.
If that wasn’t understandable, basically i want to make a list to save a datastore, more specifically for all the items in a shop, and the bool values if the player owns them.
If anyone could help, that would be so good, thanks!
If i want to get a specific value in the table, how would i do so? For example if i want to know if “waluigi” is true or false. (This is for other stuff related to this code of course)
local DatastoreService = game:GetService("DataStoreService")
local DatastoreName = "DatastoreNameTest1"
local Datastore = DatastoreService:GetDataStore(DatastoreName)
local function SaveList(Player, List)
--[[
The 'List' parameter should be a table/array, like this:
local list = {
waluigi = false;
wario = true;
luigi = false;
mario = false;
bowser = true;
}
The 'Player' parameter would be equal to the player who's owned items you are saving
]]
if Player and Player:IsA("Player") then -- Checking if the Player and List are the correct things
if List and typeof(List) == "table" then
local Key = "Player_"..tostring(Player.UserId) -- The key, which will be used to save the list for the player
local isSuccess = pcall(function()
Datastore:SetAsync(Key, List)
end)
end
end
end
local function GetList(Player)
--[[
The 'Player' parameter would be equal to the player who's owned items you are getting/reading
]]
if Player and Player:IsA("Player") then -- Checking if the Player and List are the correct things
local Key = "Player_"..tostring(Player.UserId) -- The key, which will be used to retrieve the list for the player
local Response
local isSuccess = pcall(function()
Response = Datastore:GetAsync(Key)
end)
if isSuccess and Response ~= nil then
if typeof(Response) == "table" then
return Response
end
end
end
end
--[[
What the functions return:
SaveList - nothing/nil
GetList - The requested list/nil (if not saved yet)
]]