Do you by any chance have game:BindToClose()
anywhere in any script?
Not located in any script so far
That particular error is just a warning - it doesn’t necessarily mean data hasn’t been saved. It can happen on and off when you access multiple data stores at the same time. Are you using one DataStore
for all stats, or are you using any others?
I think we’re on to something. My DataStore is in one script, but It started off with a repeat of something. I should go check that
I looked through it, and it seems that there isn’t any double datastore in there.
local DataStoreService = game:GetService("DataStoreService")
local PlayerDataStore = DataStoreService:GetDataStore("PlayerDataStore")
local Players = game:GetService("Players")
local Workspace = game:GetService("Workspace")
Players.PlayerAdded:Connect(function(player)
local leaderstats = player:FindFirstChild("leaderstats")
if not leaderstats then
leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local values = {"Wins", "Stage", "Coins"}
for _, valueName in ipairs(values) do
local value = Instance.new("IntValue")
value.Name = valueName
value.Parent = leaderstats
end
end
local success, errorMsg = pcall(function()
local playerData = PlayerDataStore:GetAsync(tostring(player.UserId)) or {}
player.leaderstats.Stage.Value = playerData.Stage or 1
player.leaderstats.Wins.Value = playerData.Wins or 0
player.leaderstats.Coins.Value = playerData.Coins or 0
end)
if success then
print("Successfully loaded " .. player.Name .. "'s data")
plrToStage(player)
else
warn(errorMsg)
end
-- This is how we connect to the player respawning (Death/Reset/Etc...)
player.CharacterAdded:Connect(function()
plrToStage(player)
end)
end)
function plrToStage(plr)
repeat wait() until plr.Character and plr.Character:FindFirstChild("HumanoidRootPart")
local stagePart = game.Workspace.checkpoints:FindFirstChild(tostring(plr.leaderstats.Stage.Value))
if not stagePart then
print("Could not find stage part for checkpoint " .. tostring(plr.leaderstats.Stage.Value))
return
end
plr.Character:WaitForChild("HumanoidRootPart").CFrame = stagePart.CFrame + Vector3.new(0, 0, 0)
end
Players.PlayerRemoving:Connect(function(player)
local success, errorMsg = pcall(function()
local playerData = {
Stage = player.leaderstats.Stage.Value,
Wins = player.leaderstats.Wins.Value,
Coins = player.leaderstats.Coins.Value
}
PlayerDataStore:SetAsync(tostring(player.UserId), playerData)
print("Successfully saved " .. player.Name .. "'s data")
end)
if not success then
warn(errorMsg)
end
end)
for _, checkpoint in pairs(game.Workspace.checkpoints:GetChildren()) do
checkpoint.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
local checkpointNumber = tonumber(checkpoint.Name)
if player.leaderstats.Stage.Value < checkpointNumber then
player.leaderstats.Stage.Value = checkpointNumber
game.Workspace.SoundEffects.Coin:Play()
player.leaderstats.Coins.Value = player.leaderstats.Coins.Value +5
end
end
end)
end
The data should still be saving, requests are just being added to a queue. Are you trying to save multiple player’s data at the same time? Check any other scripts you might have that access the DataStoreService
.
Nevermind. There is double data store it seems.
And I need to correct myself again. The double datastore was just a playerremoving event.
So you have 2 PlayerRemoving
events that both access the DataStore
?
What I meant is that there are two events that either use :SetAsync or :GetAsync
You should have one of each event to be the most efficient. As I said before, that warning doesn’t mean the data is not saving, it just means multiple things are accessing the DataStore
at the same time. Check all your server-side scripts to be sure that there isn’t anything that could be causing this warning.
I’m not really sure where this could be, so I might hire somebody to pinpoint the issue exactly.
I found the issue! Thanks for taking the time to help
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.