Datastore String Value Saving Error [SLOVED]

My Goal is to Save a String value within the game with a string value but the problem is I cannot get it to work without this error popping up within this code
Screenshot 2023-03-22 173751
the other 2 values in the code save but the string value will not save because of the error
here is the code

local ds = game:GetService("DataStoreService"):GetGlobalDataStore()
local ds2 = game:GetService("DataStoreService"):GetGlobalDataStore()
local ds3 = game:GetService("DataStoreService"):GetGlobalDataStore()
game.Players.PlayerAdded:Connect(function(plr)
	wait()
	local plrkey = "id_"..plr.UserId
	local save1 = plr.leaderstats.Blocks
	local save2 = plr.leaderstats.Wins
	local save3 = plr.leaderstats.Rank
	local Saved = ds:GetAsync(plrkey)
	wait(3)
	local saved2 = ds2:GetAsync(plrkey)
	wait(5)
	local saved3 = ds3:GetAsync(plrkey)
	if Saved then
		save1.Value = Saved[1]
		wait(3)
		save2.Value = saved2[2]
		wait(5)
        save3.Value = saved3[3] --the code line where the Error happens
	else
		local NumberForSaving1 = {save1.Value}
		wait(3)
		local NumberForSaving2 = {save2.Value}
		wait(3)
		local NumberForSaving3 = {save3.Value}
		ds:GetAsync(plrkey, NumberForSaving1)
		wait(3)
		ds2:GetAsync(plrkey,NumberForSaving2)
		wait(5)
		ds3:GetAsync(plrkey,NumberForSaving3)
           
	end
end)

game.Players.PlayerRemoving:Connect(function(plr)
	ds:SetAsync("id_"..plr.UserId, {plr.leaderstats.Blocks.Value})
	wait(3)
	ds2:SetAsync("id_"..plr.UserId, {plr.leaderstats.Wins.Value})
	wait(5)
	ds3:SetAsync("id_"..plr.UserId, {plr.leaderstats.Rank.Value})
end)

Any help would be heavily Apricated

this happens when you add a SaveN.Value after the data store is created
you can check in the saved3[3] value is nil or no using a if statement
if it is nil, you can assign a predefined value, if not, you can assign the saved value

Code
local ds = game:GetService("DataStoreService"):GetGlobalDataStore()
local ds2 = game:GetService("DataStoreService"):GetGlobalDataStore()
local ds3 = game:GetService("DataStoreService"):GetGlobalDataStore()
game.Players.PlayerAdded:Connect(function(plr)
	wait()
	local plrkey = "id_"..plr.UserId
	local save1 = plr.leaderstats.Blocks
	local save2 = plr.leaderstats.Wins
	local save3 = plr.leaderstats.Rank
	local Saved = ds:GetAsync(plrkey)
	wait(3)
	local saved2 = ds2:GetAsync(plrkey)
	wait(5)
	local saved3 = ds3:GetAsync(plrkey)
	if Saved then
        if save1.Value then
		save1.Value = Saved[1]
        else
        save1.Value = 0
        end
		wait(3)
		save2.Value = Saved[2]
        else
        save2.Value = 0
        end
		wait(3)
        save3.Value = Saved[3]
        else
        save3.Value = 0
        end
	else
		local NumberForSaving1 = {save1.Value}
		wait(3)
		local NumberForSaving2 = {save2.Value}
		wait(3)
		local NumberForSaving3 = {save3.Value}
		ds:GetAsync(plrkey, NumberForSaving1)
		wait(3)
		ds2:GetAsync(plrkey,NumberForSaving2)
		wait(5)
		ds3:GetAsync(plrkey,NumberForSaving3)
           
	end
end)

game.Players.PlayerRemoving:Connect(function(plr)
	ds:SetAsync("id_"..plr.UserId, {plr.leaderstats.Blocks.Value})
	wait(3)
	ds2:SetAsync("id_"..plr.UserId, {plr.leaderstats.Wins.Value})
	wait(5)
	ds3:SetAsync("id_"..plr.UserId, {plr.leaderstats.Rank.Value})
end)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.