I went ahead and made data stores for my game and every time I set my value to anything through the server or client, the coconut and XP values don’t save, and the catfood value automatically becomes -9223372036854775808 and I have no idea why this happens. If I’m doing something wrong, please let me know. Here’s the script (server script in serverscriptservice):
local DataStoreService = game:GetService("DataStoreService")
local CatFoodDataStore = DataStoreService:GetDataStore("CatFoodDataStore")
local XPDataStore = DataStoreService:GetDataStore("XPDataStore")
local CoconutsDataStore = DataStoreService:GetDataStore("CoconutsDataStore")
game.Players.PlayerAdded:Connect(function(plr)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Archivable = true
leaderstats.Parent = plr
local CatfoodValue = Instance.new("IntValue")
CatfoodValue.Name = "CatFood"
CatfoodValue.Archivable = true
CatfoodValue.Parent = leaderstats
local XPValue = Instance.new("IntValue")
XPValue.Name = "XP"
XPValue.Archivable = true
XPValue.Parent = leaderstats
local CoconutsValue = Instance.new("IntValue")
CoconutsValue.Name = "Coconuts"
CoconutsValue.Archivable = true
CoconutsValue.Parent = leaderstats
local CatFoodData
local XPData
local CoconutsData
local success, errormessage = pcall(function()
CatFoodData = CatFoodDataStore:GetAsync(plr.UserId.."-CatFood")
XPData = XPDataStore:GetAsync(plr.UserId.."-XP")
CoconutsData = CoconutsDataStore:GetAsync(plr.UserId.."-Coconuts")
end)
if success then
CatfoodValue.Value = CatFoodData
XPValue.Value = XPData
CoconutsValue.Value = CoconutsData
else
print("There was an error getting data!")
warn(errormessage)
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
local success, errormessage = pcall(function()
CatFoodDataStore:SetAsync(plr.UserId.."-CatFood",plr.leaderstats.CatFood.Value)
XPDataStore:SetAsync(plr.UserId.."-XP",plr.leaderstats.XP.Value)
CoconutsDataStore:SetAsync(plr.UserId.."-Coconuts",plr.leaderstats.Coconuts.Value)
end)
if success then
print("Data succesfully saved!")
else
print("There was an error saving data!")
warn(errormessage)
end
end)
local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local Data1 = DataStoreService:GetDataStore("Data1")
Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
local Leaderstats = Instance.new("Folder",Player)
Leaderstats.Name = "leaderstats"
local Points = Instance.new("IntValue",Leaderstats)
Points.Name = "Points"
local Data
local PlayerID = "Player_"..Player.UserId
local Success,ErrorMessage = pcall(function()
Data = Data1:GetAsync(PlayerID)
end)
if Success then
if Data then
Points.Value = Data.Points
wait(1)
Character:WaitForChild("HumanoidRootPart").Position = Vector3.new(Data.Position:match("(.+), (.+), (.+)"))
end
else
warn(ErrorMessage)
end
end)
end)
function SaveData(player)
local Data = {
Points = player.leaderstats.Points.Value,
Position = tostring(player.Character.HumanoidRootPart.Position)
}
local PlayerID = "Player_"..player.UserId
local Success,ErrorMessage = pcall(function()
Data1:SetAsync(PlayerID,Data)
end)
end
Players.PlayerRemoving:Connect(SaveData)
game:BindToClose(function()
for _, player in ipairs(Players:GetPlayers()) do
SaveData(player)
end
end)
I got a message! This is the message: DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.Key = Player_637561750 - Studio
Its not really a error its a warning its from the Game:BindToClose() if u want to get rid of it i think u need to get RunService and do :IsStudio() or something but i dont think it really matters i also get that but it saves and loads the data!