Data save works fine, but whenever the server is shutdown, the stats do not save.
local DataStoreService = game:GetService("DataStoreService")
local inventory = DataStoreService:GetDataStore("Inventory")
local values = game.ReplicatedStorage.ShopValues.FirstWalkspeed
game.Players.PlayerAdded:Connect(function(player)
local Data
local success, err = pcall(function()
Data = inventory:GetAsync(player.UserId.."-WalkSpeed", values.Value)
end)
if success then
values.Value = Data
else
print("Error getting data")
warn(err)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local success, err = pcall(function()
inventory:SetAsync(player.UserId.."-WalkSpeed", values.Value)
end)
if success then
print ("data saved")
else
print("There was an error")
warn(err)
end
end)

5 comments
Is api service on?
Which line doesnt work?
Yeah everythings on, does it need a BindToClose?
Yes, it needs a BindToClose.
PlayerRemoving doesn't fire when the server is closing because Roblox is Bad™. Use a data cache system and on bindtoclose save any lingering player data.