Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why Can't Leaderstats Save?

There was no Error in the OutPut:

local ds = game:GetService("DataStoreService"):GetDataStore("SaveData")
game.Players.PlayerAdded:Connect(function(plr)
	wait()
	local plrkey = "id_"..plr.userId
	local save1 = plr.leaderstats.Wins
	local save2 = plr.leaderstats.Points
	
	local GetSaved = ds:GetAsync(plrkey)
	if GetSaved then
		save1.Value = GetSaved[1]
		save2.Value = GetSaved[2]
	else
		local NumberForSaving = {save1.Value, save2.Value,}
		ds:GetAsync(plrkey, NumberForSaving)
		end
end)

game.Players.PlayerRemoving:Connect(function(plr)
	ds:SetAsync("id_"..plr.userId,{plr.leaderstats.Wins.Value, plr.leaderstats.Points.Value,})
end)
game.Players.PlayerAdded:Connect(function(plr)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = plr
	
	local val = Instance.new("IntValue")
	val.Parent = leaderstats
	val.Name = "Wins"
	val.Value = 0
	
	local val2 = Instance.new("IntValue")
	val2.Parent = leaderstats
	val2.Name = "Points"
	val2.Value = 0
	
	end)


1 answer

✓ Accepted answer

maybe try this:

local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("SaveData")

game.Players.PlayerAdded:Connect(function(Player)
	local Leaderstats = Instance.new("Folder", Player)
	Leaderstats.Name = "leaderstats"
	local Currency = Instance.new("IntValue", Leaderstats)
	Currency.Name = "Wins"
	Currency.Value = 0

	local Data = DataStore:GetAsync(Player.UserId)
	if Data then
		Currency.Value = Data
	end
end)

game.Players.PlayerRemoving:Connect(function(Player)
	DataStore:SetAsync(Player.UserId, Player.leaderstats.Wins.Value)
end)

game.Players.PlayerRemoving:Connect(function(Player)
	DataStore:SetAsync(Player.UserId, {
		["Money"] = Player.leaderstats.Wins.Value;
	})
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.