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

Is there a limit to how much a datastore can save?

So I'm trying to save at least 4 value/ leaderstats in my game, but I found out that when I played, it only saves the first 2 stats, the other 2 stats didn't save.

Script:

local DSService = game:GetService("DataStoreService"):GetDataStore("Stage4")

game.Players.PlayerAdded:connect(function(plr)
	-- Define variables
	local uniquekey = 'id-'..plr.userId
	
	local leaderstats = Instance.new('IntValue', plr)
	leaderstats.Name = "leaderstats"
	
	local Stage =  Instance.new('IntValue',leaderstats)
	Stage.Name = "Stage"
	Stage.Value = 0
	
	local Gems = Instance.new("NumberValue",leaderstats)
	Gems.Name = "Gems"
	Gems.Value = 0
	
	local Skip = Instance.new("NumberValue",plr)
	Skip.Name = "Skip"
	Skip.Value = 0
	
	local StageSkipped = Instance.new("NumberValue",leaderstats)
	StageSkipped.Name = "StageSkipped"
	StageSkipped.Value = 0
	
	-- GetAsync
	local GetSaved = DSService:GetAsync(uniquekey)
	if GetSaved then
		Stage.Value = GetSaved[1]
		Gems.Value = GetSaved[2]
		StageSkipped.Value = GetSaved[3]
	else
		local NumbersForSaving = {Stage.Value, Gems.Value, StageSkipped.Value, Skip.Value}
		DSService:SetAsync(uniquekey, NumbersForSaving)
	end
end)


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

I don't think there is anything wrong with it, just that it wouldn't save the last 2 values/stats. Any help would be appreciated. Thanks!

2 comments

0

Im having a similar issue with my datastore, but the script is quite a bit bigger. hopefully you figure it out.

0

in answer to your question yes i believe so but you are WELL below that threshhold

1 answer

✓ Accepted answer

I notated where I believe the issue was in the code. Let me know if im wrong.

local DSService = game:GetService("DataStoreService"):GetDataStore("Stage4")

game.Players.PlayerAdded:connect(function(plr)
    -- Define variables
    local uniquekey = 'id-'..plr.userId

    local leaderstats = Instance.new('IntValue', plr)
    leaderstats.Name = "leaderstats"

    local Stage =  Instance.new('IntValue',leaderstats)
    Stage.Name = "Stage"
    Stage.Value = 0

    local Gems = Instance.new("NumberValue",leaderstats)
    Gems.Name = "Gems"
    Gems.Value = 0

    local Skip = Instance.new("NumberValue",plr)
    Skip.Name = "Skip"
    Skip.Value = 0

    local StageSkipped = Instance.new("NumberValue",leaderstats)
    StageSkipped.Name = "StageSkipped"
    StageSkipped.Value = 0

    -- GetAsync
    local GetSaved = DSService:GetAsync(uniquekey)
    if GetSaved then
        Stage.Value = GetSaved[1]
        Gems.Value = GetSaved[2]
        StageSkipped.Value = GetSaved[3]
	Skip.Value = GetSaved[3] -- you missed this one
    else
        local NumbersForSaving = {Stage.Value, Gems.Value, StageSkipped.Value, Skip.Value}
        DSService:SetAsync(uniquekey, NumbersForSaving)
    end
end)


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

3 comments

0

I editted my answer

0

oh yes that might be the problem... let me test.

0

I also just realized I had that as [3] instead of [4]! I’m sure you’ve already noticed though

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