I’m trying to make a tycoon, but the datastores aren’t working properly and are unreliable too.
What is happening is: sometimes the button doesn’t get removed, sometimes the object doesn’t load at all. I don’t know why this happens, this is a huge roadblock for me, i want this working before working on other stuff, without this fixed my tycoon cannot be released.
Saving and loading code:
local function saveTycoon(plr)
local buttons = cs:GetTagged(tagname)
local saveTable = {}
for _, button in ipairs(buttons) do
if button:FindFirstChild("Tycoon") and button:FindFirstChild("Bought") and button:FindFirstChild("Object") then
if button.Tycoon.Value == tycoon and button.Bought.Value == true then
table.insert(saveTable, button.Object.Value.Name)
end
end
end
-- Save DataStore
local success, errorMessage = pcall(function()
tycoonStore:SetAsync(plr.UserId, saveTable)
end)
if not success then
warn("Failed to save tycoon data: " .. errorMessage)
end
end
local function loadTycoon(plr)
local success, tycoonData = pcall(function()
return tycoonStore:GetAsync(plr.UserId)
end)
if success and tycoonData then
local buttons = cs:GetTagged(tagname)
for _, objectName in ipairs(tycoonData) do
local obj = objectfolder:FindFirstChild(objectName)
if obj then
obj.Parent = tycoon
for _, button in ipairs(buttons) do
if button:FindFirstChild("Tycoon") and button:FindFirstChild("Object") and button:FindFirstChild("Bought") then
if button.Tycoon.Value == tycoon and button.Object.Value == obj then
button.Bought.Value = true
button.Parent = objectfolder
break
end
end
end
else
warn("Object not found: " .. objectName)
end
end
else
warn("Failed to load tycoon data or data is empty.")
end
end
Thanks for help in advance!