I already have a leaderstat with a DataStore (points) I'm trying to create a new leaderstat called Level, but it either overwrites my other leaderstat, Points or takes Points's Value or creates a new leaderstat called Value

local DSService = game:GetService('DataStoreService'):GetDataStore('Hamburger8288013')
game.Players.PlayerAdded:connect(function(plr)
local uniquekey = 'id-'..plr.userId
local leaderstats = plr:WaitForChild('leaderstats')Instance.new('IntValue', leaderstats)
local savevalue = Instance.new('IntValue')
leaderstats.Name = 'leaderstats'
savevalue.Parent = leaderstats
savevalue.Name = 'Level'

--Get Async--
local GetSaved = DSService:GetAsync(uniquekey)
if GetSaved then
	savevalue.Value = GetSaved[1]
else
	local NumersForSaving = {savevalue.Value}
	DSService:SetAsync(uniquekey, NumersForSaving)
end
end)

game.Players.PlayerRemoving:connect(function(plr)
local uniquekey = 'id-'..plr.userId
local Savetable = {plr.leaderstats.Level.Value}
DSService:SetAsync(uniquekey, Savetable)	
end)


2 comments

0

I don't know what you mean by multiple leaderstats but you can have multiple data store names, use different key prefixes or save more data in the table.

0

Multiple leaderstats = one leaderstat for points and another for level. That doesn't work for some reason.