Hello, I wanted to test a part of my script of the backup of data, by removing playerremoving and bindtoclose to see if only, the script (which is below) allows to make a backup of data regularly except that there is a problem. In fact if I wait 30 seconds in game and I quit and come back then the backup will be done (the one induced by the remote events), but if when the remots event fires (and I receive on the output that the data is saved) and I quit in the first seconds after receiving the message in the output, the backup will not be done. Does anyone know why? Sorry if it’s difficult to understand, I don’t speak English very well, I can rephrase if necessary. Thank you
game.ReplicatedStorage.Nametag.OnServerEvent:Connect(function(plr)
local creatures = plr.Creatures
local data = {}
for _, creature in pairs(creatures:GetChildren()) do
table.insert(data, creature.Name)
end
local success, response = pcall(function()
saveCreatures:SetAsync(plr.UserId, data)
end)
if success then
print("DataSave")
end
if not success then
warn()
end
end)
It is as if the server receives the information that it is necessary to save the data, but it does it 20 or 30 seconds later, instead of immediately as when the player leaves the game. Someone know why ?
If the remots event fire (ouput: DataSave) and I wait 30 seconds then I leave the game and come back then the data will be saved. But if the remots event fire (output: DataSave) and I leave in the first 10 or 20 seconds and I come back then the data will not be saved and I will have my old data. Very strange ?
From what I’m gathering, your script is saving player data every 30 seconds which begins when the player joins. This would explain why when you leave after only 10-20 seconds, your data doesn’t save. Can you send your client-side code?
Thank you for your answer. Indeed, between the moment when it is indicated in the output that the data is saved (at the moment when the server sends the information to save the data) and the moment when the data is really saved, it takes about twenty or thirty seconds (I did not time it). So if after ten seconds or so after the last save request is sent I quit the game, it will not take effect and I will come back with the data from before.
Here is the complete script without the bindtoclose and playerremoving (intentionally, to make sure that the backup doesn’t need these two functions to be done, for more security) . Thank you
local function onLoad(player)
local data
local success = pcall(function()
data = saveCreatures:GetAsync(player.UserId)
end)
if success then
if not data then
data = {}
end
local creatures = Instance.new("Folder")
creatures.Name = "Creatures"
creatures.Parent = player
local value = Instance.new("BoolValue")
value.Name = "playerok"
value.Parent = player
for _, creature in pairs(data) do
if workspace.Creatures:FindFirstChild(creature) then
local bool = Instance.new("BoolValue")
bool.Name = creature
bool.Parent = creatures
end
end
isLoaded[player] = true
else
player:Kick("Your data failed to load ! We are sorry, Please rejoin")
end
end
game.ReplicatedStorage.Nametag.OnServerEvent:Connect(function(plr)
local creatures = plr.Creatures
local data = {}
for _, creature in pairs(creatures:GetChildren()) do
table.insert(data, creature.Name)
end
local success, response = pcall(function()
saveCreatures:SetAsync(plr.UserId, data)
end)
if success then
print("DataSave")
end
if not success then
warn()
end
end)
Players.PlayerAdded:Connect(onLoad)