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

Cannot store Array in DataStore WHY?

19:33:57.776 - 104: Cannot store Array in DataStore

local module = {}

function module:CharSetData()
end

local data = game:GetService('DataStoreService'):GetDataStore('CharDataLol')

game.Players.PlayerAdded:Connect(function(player) -- Player joins
	
	--[]--------------------------------------------------
	
	--[Settings]
	local CharacterSettings =    Instance.new("Configuration",player)
	
	local HelmetColour =         Instance.new("Color3Value",CharacterSettings)
	local HelmetLivery =         Instance.new("StringValue",CharacterSettings)
	local ShirtID =              Instance.new("StringValue",CharacterSettings)
	local PantsID =              Instance.new("StringValue",CharacterSettings)
	local Country =              Instance.new("StringValue",CharacterSettings)
	
	--[Skin Settings]
	local BodyColors =           Instance.new("BodyColors",CharacterSettings)
	
	--[Extra]
	local TimePlayed =           Instance.new("IntValue",CharacterSettings)
	
	--[NAMES AND VALUES]----------------------------------------------
	
	--[Settings]
	CharacterSettings.Name =    "CharacterSettings"
	
	HelmetColour.Name =         "HelmetColour"
	HelmetColour.Value =        Color3.fromRGB(248, 248, 248)
	
	HelmetLivery.Name =         "HelmetLivery"
	HelmetLivery.Value =        ""
	
	ShirtID.Name =              "ShirtID"
	ShirtID.Value =             ""
	
	PantsID.Name =              "PantsID"
	PantsID.Value =             ""
	
	Country.Name =              "Country"
	Country.Value =	            "UK"
		
    --[Skin Settings]
	BodyColors.Name =           "BodyColors"
	
	--[Bosy Parts]
	BodyColors.HeadColor3     = Color3.fromRGB(0, 0, 0)
	BodyColors.LeftArmColor3  = Color3.fromRGB(0, 0, 0)
	BodyColors.RightArmColor3 = Color3.fromRGB(0, 0, 0)
	BodyColors.LeftLegColor3  = Color3.fromRGB(0, 0, 0)
	BodyColors.RightLegColor3 = Color3.fromRGB(0, 0, 0)
	BodyColors.TorsoColor3    = Color3.fromRGB(0, 0, 0)

	
	--[Extra]
	TimePlayed.Name  =       "TimePlayed"
	TimePlayed.Value =       "0000000000"
	
	--[Cases]

	--[]----------------------------------------------------
	
	key = 'usertest_'..player.userId -- This is like the 'identity' of what you are saving;
	-- It stores the datas of a certain player;
	-- I used userId because of simplicity;
	-- You could use names, if you want.
	
	if data:GetAsync(key) ~= nil then -- Checks if the Player has any saved data;
		
		HelmetColour       = data:GetAsync(key)[1]
		HelmetLivery.Value = data:GetAsync(key)[2]
		ShirtID.Value      = data:GetAsync(key)[3]
		PantsID.Value      = data:GetAsync(key)[4]
		Country.Value      = data:GetAsync(key)[5]
		TimePlayed.Value   = data:GetAsync(key)[6]
	
	else -- If the player does not have any saved data, then...
		data:SetAsync(key, {0,0,0,0,0,0,0}) -- The script will create new save data for them.

	end
end)

game.Players.PlayerRemoving:connect(function(player) -- Player leaves
	key = 'usertest_'..player.userId -- Key again
	
	local save = {
		player.CharacterSettings.HelmetColour.Value,
		player.CharacterSettings.HelmetLivery.Value,
		player.CharacterSettings.ShirtID.Value,
		player.CharacterSettings.PantsID.Value,
		player.CharacterSettings.Country.Value,
		player.CharacterSettings.BodyColors.Value,
		player.CharacterSettings.TimePlayed.Value
		
	} 
	
	data:SetAsync(key, save) -- Saves the table named 'save'
	
	end)

return module

1 comment

0

The parent argument to Instance.new is deprecated, parent as the last property. userId and connect are deprecated, use UserId and Connect

1 answer

I believe you're exceeding the data transfer limit...

You can have no more than 260,000 characters in a single datastore value.

"Character count in string cannot exceed max size of 64*1024"

http://robloxdev.com/articles/JSON-Storage-Format

2 comments

0

this is all so confusing

0

The answer is basically saying your data value is over 260k chars. Make it smaller.

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