Hello! I’m currently making a game that saves heavy amounts of data. How I have it set up, is that when the player leaves save the load of data. Currently i have 3 seperate player removing scripts that detect when the player leaves then saves data. For 2 of the 3 saving data events. one saves a table of 34 values whilst the other saves a dictionary of 34 values.
on the remaining data saving script it saves a large string of data pertaining 14 different Int values.
I’m having issues, as sometimes the data doesn’t save. Should i try to make data saving scripts that contain large amounts of information but less requests, or should I make many requests with small amounts of info?
I wish I could save more data but Roblox is unable to provide this as a feature. Even with their billions…
What should i do as an alternative?
Is 3 removing player events too many or do those 3 removing player event contain too much information?
Even when it works, It still sometimes doesn’t save certain information (It doesn’t save coins/gems if you join, buy something, then leave but saves the information you own the item which lets players get free items from the shop)
So when in studio and closing the server you were on you cant use a simple player removing because the server is removing before the player scripts can run so you have to use bind to close to bind a save all data function but all players data is deleted by then so you have to simutaniously store all their data in tables inside the script so that when a player leaves and the server closes it still has the data to set
ok this should work and fix all your problems, if something dosent work tell me
local Datastores = game:GetService("DataStoreService")
local ExperienceStorage = Datastores:GetDataStore("PlayerExperience")
local ServerActive = true
local PlayerData = {}
local function setdata(Player, DataName, Val)
PlayerData[Player.UserId..DataName] = Val
ExperienceStorage:SetAsync(Player.UserId..DataName, Val)
end
local function getdata(Player, DataName)
local HI = ExperienceStorage:GetAsync(Player.UserId..DataName)
if not HI then HI = {0,0,0,0,0,0,0,0,0,0,0,1,0,0} end
return HI
end
game.Players.PlayerAdded:Connect(function(Player)
repeat wait() until Player.PlayerGui:FindFirstChild("ScreenGui")
local ScreenGui = Player.PlayerGui:FindFirstChild("ScreenGui")
repeat wait() until ScreenGui:FindFirstChild("Small") and ScreenGui:FindFirstChild("Mid") and ScreenGui:FindFirstChild("Long") and ScreenGui:FindFirstChild("Coins") and ScreenGui:FindFirstChild("Gems") and ScreenGui:FindFirstChild("Progress") and ScreenGui:FindFirstChild("Lv")
local Data = getdata(Player, 'Data')
ScreenGui.Small.Value = Data[1]
ScreenGui.Mid.Value = Data[2]
ScreenGui.Long.Value = Data[3]
ScreenGui.SmallMoving.Value = Data[4]
ScreenGui.MidMoving.Value = Data[5]
ScreenGui.LongMoving.Value = Data[6]
ScreenGui.Wallpaper.Value = Data[7]
ScreenGui.Crosshair.Value = Data[8]
ScreenGui.Coins.Value = Data[9]
ScreenGui.Gems.Value = Data[10]
ScreenGui.Progress.Value = Data[11]
ScreenGui.Lv.Value = Data[12]
ScreenGui.Lv_Boost.Value = Data[13]
ScreenGui.Coin_Boost.Value = Data[14]
end)
game.Players.PlayerRemoving:Connect(function(Player)
wait(0.1)
if ServerActive then setdata(Player, 'Data', PlayerData[Player.UserId]) end
end)
game:BindToClose(function()
ServerActive = false
for Key, PlayerData in pairs(PlayerData) do
ExperienceStorage:SetAsync(Key, PlayerData)
end
end)
i have 2 other datastore scripts that save a table and a dictionary. Since that information is accessible even after the player leaves to the server, is that fine?
Hey i just tested the code and it doesnt appear to have saved the information. I changed the coins value on the server then rejoined the game and the coins value went to 0. I tested this multiple times and results did not vary.
edit: after some debugging i found out when the player joins the game it doesn’t find the players data with your method and goes to the nil check which resets all the stats
also the script works for me just set it up, try making sure all of the values that are set on playeradded are there bc if even 1 of them is missing or not named correctly it will stop itself