Hello there,
Okay ima just get straight into it. So I made this datastore script for my game and I don’t know why but every time I leave the game i get a warning in the output saying this.
local DataStore = game:GetService("DataStoreService")
local PlayerCash = DataStore:GetDataStore("PlayerCash")
local PlayerLoan = DataStore:GetDataStore("PlayerLoan")
function Leaderstats(plr)
local stats = Instance.new("Folder", plr)
stats.Name = "leaderstats"
local pounds = Instance.new("IntValue", stats)
pounds.Name = "Pounds"
pounds.Value = 0
local bounty = Instance.new("NumberValue", stats)
bounty.Name = "Bounty"
bounty.Value = 0
local kms = Instance.new("IntValue", stats)
kms.Name = "Kms"
kms.Value = 0
local loan = Instance.new("IntValue", plr)
loan.Name = "Loan"
loan.Value = 0
plr.CharacterAdded:Connect(function()
saving(plr)
end)
end
function OnPlayerAdded(player)
wait(2)
local plrkey = "id_"..player.UserId
local loanKey = "loan_"..player.UserId
local leaderstats = player:WaitForChild("leaderstats")
local success, message = pcall(function()
local data = PlayerCash:GetAsync(plrkey)
local data2 = PlayerLoan:GetAsync(loanKey)
if data and #data == 3 then
leaderstats.Pounds.Value = data[1]
leaderstats.Bounty.Value = data[2]
leaderstats.Kms.Value = data[3]
end
if data2 then
leaderstats.Loan.Value = data2
end
end)
if not success then
warn("Error loading data for player " .. player.Name .. ": " .. message)
end
end
function saving(player)
local leaderstats = player:FindFirstChild("leaderstats")
if leaderstats then
local success, message = pcall(function()
local data = {
leaderstats.Pounds.Value,
leaderstats.Bounty.Value,
leaderstats.Kms.Value
}
PlayerCash:SetAsync("id_"..player.UserId, data)
PlayerLoan:SetAsync("loan_"..player.UserId, leaderstats.Loan.Value)
end)
if not success then
warn("Error saving data for player " .. player.Name .. ": " .. message)
end
end
end
function bindingwhenclosing()
for _, player in ipairs(game:GetService("Players"):GetPlayers()) do
saving(player)
end
end
game:GetService("Players").PlayerAdded:Connect(function(plr)
Leaderstats(plr)
OnPlayerAdded(plr)
end)
game:GetService("Players").PlayerRemoving:Connect(function(plr)
saving(plr)
end)
game:BindToClose(bindingwhenclosing)
Please feel free to ask question’s and ect cause idk why It’s done this thank you