local DataStoreService = game:GetService("DataStoreService")
local PartsStore = DataStoreService:GetDataStore("PlayerParts")
local data = 0
game:GetService("Players").PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder", player)
leaderstats.Name = "leaderstats"
local PartColor = Instance.new("Color3Value", leaderstats)
PartColor.Name = "Color"
PartColor.Value = Color3.new(255,255,255)
local Parts = Instance.new("IntValue", leaderstats)
Parts.Name = "Parts"
local playerUserID = ("Player_" .. player.UserId)
local success, errorMessage = pcall(function()
data = PartsStore:GetAsync(playerUserID)
end)
if success then
Parts.Value = data
else
print("Player's data wen't no")
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local playerUserID = ("Player_" .. player.UserId)
local data = player.leaderstats.Parts.Value
local success, errorMessage = pcall(function()
PartsStore:SetAsync(playerUserID, data)
end)
if success then
print("Data Saved")
else
print("Data Fricked Up")
end
end)
function onShutDown()
task.wait(4)
end
game:BindToClose(onShutDown)
This is the same as yours but it has the closing function.
We are using something called BindToClose()
This when the server shut downs it waits 4 seconds to save every player data.
Here is an example
function onShutDown()
-- Server is shutting down, There is no time to save players data.
task.wait(4) -- It will wait 4 seconds then closes the server. Now we have time to save the data!
end
game:BindToClose:Connect(OnShutDown)
you have something else going on there then.
you said it is loading the player leaderstats?
setup a warn print at the bottom of your addplayer and the bottom of your player removing and also one at the bottom of the script see if any show in output