-
What do you want to achieve? I am creating a find the __ (like find the markers), and I want to create a system where it saves whether or not you have collected a certain marker (im not making find the markers but ill just use it). However, I want to make a system that looks through a folder in the workspace and creates boolvalues with the name of the certain marker; then when you leave or join it saves/loads the values back in.
-
What is the issue? I already did most of what I am trying to achieve, but I am having trouble with the saving and loading in part. First off, for my saving, whenever I try and print it, all the values return as nil, and I am unsure why. For the loading, I honestly do not know how to load in the values equal to what they were when you left.
-
What solutions have you tried so far? I looked through the devforum and devhub of tables, metatables, dictionaries, and other people who had this question, but I still could not figure out how to get this to work with the code I have.
my code:
local DataStoreService = game:GetService("DataStoreService")
local myDataStore = DataStoreService:GetDataStore("myDataStore")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
--Create the bool values
for _, child in ipairs(game.Workspace.MainZone.SpiderHorses:GetChildren()) do
local bool = Instance.new("BoolValue")
bool.Name = child.Name.." Horse"
bool.Parent = player:WaitForChild("leaderstats")
end
local playerUserId = "Player_"..player.UserId
-- Load Data
local data
local success, errormessage = pcall(function()
data = myDataStore:GetAsync(playerUserId)
end)
if success then
--i have no idea how to load in the data from my previous table
end
--
end)
game.Players.PlayerRemoving:Connect(function(player)
local playerUserId = "Player_"..player.UserId
local data = {}
-- Saves values that currently exist.
for _, child in ipairs(player.leaderstats:GetDescendants()) do -- change this to your item
table.insert(data, child.Value)
end
local success, errormessage = pcall(function()
myDataStore:SetAsync(playerUserId, data)
end)
if success then
print("Data Successful")
else
print("Nope")
warn(errormessage)
end
end)