Hello, Ive been having this problem for months,I just have no clue how to make a players progress save in a tycoon. I have a DataStore script, and I have tried putting Bool values in that script and setting them to true for each tycoon object, but it is not working. Plz help!
Here is the script im trying to use:
local DataStoreService= game:GetService('DataStoreService'):GetDataStore("PretendCodeIsHere") local RunService = game:GetService("RunService") local db = 3 function SaveTableFunc(player) local SaveTable = { player={Mine = true} } return SaveTable end game.Players.PlayerAdded:connect(function(player) repeat wait() until player.Character repeat wait() until script:FindFirstChild("stats") local save1 = script.stats:Clone() save1.Parent = player local stats = player.stats local save = SaveTableFunc(player) local playerkey = "player-"..player.userId local SaveFiles = DataStoreService:GetAsync(playerkey) function dataInput(player, save) stats.bank.Value = SaveFiles.bank print("Got saved data for "..player.Name) end local Passed, Error = pcall(function() if SaveFiles == nil then print(player.Name.." has no save data yet") else dataInput(player, save) end end) if Error then print("***ERROR GETTING SAVE FILE FOR "..player.Name) local attempts = 0 while wait(db) do local retries = attempts + 1 attempts = retries local pass,err = pcall(function() if SaveFiles == nil then print(player.Name.." has no save data yet") else dataInput(player, save) end end) if pass or attempts == 5 then break end end end end) function SaveData(player) local Success,Error = pcall(function() local playerkey = "player-"..player.userId local save = SaveTableFunc(player) DataStoreService:SetAsync(playerkey,save) print("Saved data for "..player.Name) end) if Error then print("***ERROR SAVING DATA FOR "..player.Name) local attempts = 0 while wait (db) do local retries = attempts + 1 attempts = retries local pass,fail = pcall(function() local playerkey = "player-"..player.userId local data = SaveData(player) DataStoreService:SetAsync(playerkey,save) print("Successfully saved data for "..player.Name) end) if pass or attempts == 10 then break end end end end game.Players.PlayerRemoving:Connect(SaveData) game:BindToClose(function() if RunService:IsStudio() then return end local Players = game:GetService("Players") for _,player in pairs(Players:GetPlayers()) do SaveData(player) print("Saved data for "..player.Name.." on shutdown.") end end)
Im also using ZedNovs tycoon kit Idk if that makes a difference.