local dataStoreService = game:GetService("DataStoreService")
local killSave = dataStoreService:GetDataStore("PlayerKills")
game.Players.PlayerAdded:Connect(function(player)
local totalKills
local success, err = pcall(function()
totalKills = killSave:GetASync("Player_"..player.UserId)
end)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local kills = Instance.new("IntValue")
kills.Name = "Kills"
if success then
kills.Value = totalKills
else
kills.Value = 0
end
kills.Parent = leaderstats
local rank = Instance.new("StringValue")
rank.Name = "Rank"
rank.Value = "Human"
rank.Parent = leaderstats
local function updateKills(newKills)
if newKills then
if newKills >= 25 then
rank.Value = "Supreme"
end
if newKills >= 100 then
rank.Value = "Sage"
end
end
end
updateKills()
kills.Changed:Connect(updateKills)
end)
local function save(player)
local success, err = pcall(function()
killSave:SetAsync("Player_"..player.UserId, player.leaderstats.Kills.Value)
end)
if success then
print("saved successfully")
else
print("failed to save")
end
end
local function autosave()
while wait(15) do
for i, player in pairs(game:GetService("Players"):GetPlayers()) do
print("saving")
save(player)
end
end
end
spawn(autosave)
game.Players.PlayerRemoving:Connect(function(player)
save(player)
end)
I have API Services allowed so I have no clue what causes the data to not store.

1 comment
Are you only testing on roblox studio? I had a similar problem where data wont save but when I tested in the actual game it suddenly worked.