Hello everyone!
I've been trying to impliment DataStore2 in saving my items in game! The items are in a table or folder if you will, placed inside the LocalPlayers Leaderstats
It saves the coins without any trouble, but won't save the Items list as it gives the Infinite Yield error code. I am assuming that the problem is where the items are boolean values, and I just don't entirely know how to go about datastoring these boolean values, so I've turned to here!
My code below will provide my attempt at doing so, in which caused the error statement to pop up!
Thank you for everyones help, and I appreciate it!
My Script:
local players = game:GetService("Players")
local stats = {
{"Coins", 20000},
{"Items", 0},
{"Inventory", nil}
}
players.PlayerAdded:Connect(function(player)
local folder = Instance.new("Folder")
folder.Name = "leaderstats"
folder.Parent = player
for i,v in pairs(stats) do
local statType = "IntValue"
local name = v[1]
local value = v[2]
if type(value) == "boolean" then
statType = "BoolValue"
elseif type(value) == "string" then
statType = "StringValue"
elseif value == nil then
statType = "Folder"
end
local stat = Instance.new(statType)
stat.Name = name
if value then stat.Value = value end
stat.Parent = folder
end
local DataStore2 = require(game.ServerScriptService:WaitForChild("MainModule"))
local coinsDataStore = DataStore2("coins",player)
local itemsDataStore = DataStore2("items",player)
local function coinsUpdate(updatedValue)
folder:WaitForChild("Coins").Value = coinsDataStore:Get(updatedValue)
end
coinsUpdate(folder:WaitForChild("Coins").Value)
coinsDataStore:OnUpdate(coinsUpdate)
local function itemsUpdate(updatedValue)
folder:WaitForChild("items").Value = itemsDataStore:Get(updatedValue)
end
itemsUpdate(folder:WaitForChild("items").Value)
itemsDataStore:OnUpdate(itemsUpdate)
end)

1 comment
Sometimes it's something dumb, lol. Thanks so much!