Data store not working

Hello!
I’ve been working on my game and I made a datastore. (Well, I didnt actually make it. It was from a tutorial.)

My datastore has been working!.. but…
It seems it has a ‘capacity’

If I am saving more than 4 values, well, it just doesnt save.
This might not be a problem with my script, but i’ll show you it anyways.

local dataStoreService 	= game:GetService("DataStoreService")
local clientDataStore = dataStoreService:GetDataStore("DataStore")

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		local Values = Instance.new("Folder")
		Values.Name = "Values"
		Values.Parent = plr
		
		local SpecialDamage = Instance.new("IntValue")
		SpecialDamage.Name = "SpecialDamage"
		SpecialDamage.Parent = Values
		
		local SpecialCritDamage = Instance.new("IntValue")
		SpecialCritDamage.Name = "SpecialCritDamage"
		SpecialCritDamage.Parent = Values
		
		local Level = Instance.new("IntValue")
		Level.Name = "Level"
		Level.Parent = Values
		
		local NumberOfAbnormalStats = Instance.new("IntValue")
		NumberOfAbnormalStats.Name = "NumberOfAbnormalStats"
		NumberOfAbnormalStats.Parent = Values
		
		local NumOfKicks = Instance.new("IntValue")
		NumOfKicks.Name = "NumOfKicks"
		NumOfKicks.Parent = Values


		local SpecialEnabled = Instance.new("BoolValue")
		SpecialEnabled.Name = "SpecialEnabled"
		SpecialEnabled.Parent = Values

		local Beheaded = Instance.new("BoolValue")
		Beheaded.Name = "Beheaded"
		Beheaded.Parent = Values
		
		local SwingSpecial = Instance.new("BoolValue")
		SwingSpecial.Name = "SwingSpecial"
		SwingSpecial.Parent = Values
		
		local StunSpecial = Instance.new("BoolValue")
		StunSpecial.Name = "StunSpecial"
		StunSpecial.Parent = Values

		local playerUserId = "Player_"..plr.UserId

		--load player data--

		local data
		
		local success, errormessage = pcall(function()
			data = clientDataStore:GetAsync(playerUserId)
		end)

		if success then

			SpecialDamage.Value = data.SpecialDamage
			
			SpecialCritDamage.Value = data.SpecialCritDamage
			
			NumberOfAbnormalStats.Value = data.NumberOfAbnormalStats
			
			NumOfKicks.Value = data.NumOfKicks
			
			--SwingSpecial.Value = data.SwingSpecial
			
			--StunSpecial.Value = data.StunSpecial
			
			--Level.Value = data.Level
		end
	end)
end)

function saveData(plr)
	local playerUserId = "Player_"..plr.UserId
	
	local data = {
		SpecialDamage = plr.Values.SpecialDamage.Value,
		
		SpecialCritDamage = plr.Values.SpecialCritDamage.Value,
		
		NumberOfAbnormalStats = plr.Values.NumberOfAbnormalStats.Value,
		
		NumOfKicks = plr.Values.NumOfKicks.Value,
		
		--SwingSpecial = plr.Values.SwingSpecial,
		
		--StunSpecial = plr.Values.StunSpecial,
		
		--Level = plr.Values.Level.Value
	}
	
	local success, errormessage = pcall(function()
		clientDataStore:SetAsync(playerUserId, data)
	end)
	
	if success then
		print("data successfully saved for "..playerUserId)
	else
		print("error saving data for "..playerUserId)
	end
end

game.Players.PlayerRemoving:Connect(saveData)
 

The reason why there is “–” in some parts is because it just wouldnt work if I got rid of the comments.
Like I said, it cant hold more than 4 values.
and I need more than 4.

Any help is appreciated.

Store a table

local datathing = {thecoinsorsomething,anotherstatorsomething} -- etc
datastore:SetAsync(key,datathing)

local fetch = datastore:GetAsync(key)
coins.value = fetch[1] -- do this kind of but like in the order of what you stored

sorry if that doesn’t make any sense


Yeah, it doesnt make sense. Where would I put the "coins.value = fetch[1]
And how would I put the instance.new stuff

(i am new to scripting)

Try this new code (not tested)

local dataStoreService 	= game:GetService("DataStoreService")
local clientDataStore = dataStoreService:GetDataStore("DataStore")

game:GetService("Players").PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		local Values = Instance.new("Folder")
		Values.Name = "Values"
		Values.Parent = plr

		local SpecialDamage = Instance.new("IntValue")
		SpecialDamage.Name = "SpecialDamage"
		SpecialDamage.Parent = Values

		local SpecialCritDamage = Instance.new("IntValue")
		SpecialCritDamage.Name = "SpecialCritDamage"
		SpecialCritDamage.Parent = Values

		local Level = Instance.new("IntValue")
		Level.Name = "Level"
		Level.Parent = Values

		local NumberOfAbnormalStats = Instance.new("IntValue")
		NumberOfAbnormalStats.Name = "NumberOfAbnormalStats"
		NumberOfAbnormalStats.Parent = Values

		local NumOfKicks = Instance.new("IntValue")
		NumOfKicks.Name = "NumOfKicks"
		NumOfKicks.Parent = Values


		local SpecialEnabled = Instance.new("BoolValue")
		SpecialEnabled.Name = "SpecialEnabled"
		SpecialEnabled.Parent = Values

		local Beheaded = Instance.new("BoolValue")
		Beheaded.Name = "Beheaded"
		Beheaded.Parent = Values

		local SwingSpecial = Instance.new("BoolValue")
		SwingSpecial.Name = "SwingSpecial"
		SwingSpecial.Parent = Values

		local StunSpecial = Instance.new("BoolValue")
		StunSpecial.Name = "StunSpecial"
		StunSpecial.Parent = Values

		local playerUserId = "Player_"..plr.UserId

		--load player data--

		local data

		local success, errormessage = pcall(function()
			data = clientDataStore:GetAsync(playerUserId)
		end)

		if success then

			SpecialDamage.Value = data[1]

			SpecialCritDamage.Value = data[2]

			NumberOfAbnormalStats.Value = data[3]

			NumOfKicks.Value = data[4]

			SwingSpecial.Value = data[5]

			StunSpecial.Value = data[6]

			Level.Value = data[7]
		end
	end)
end)

function saveData(plr)
	local playerUserId = "Player_"..plr.UserId

	local data = {
		plr.Values.SpecialDamage.Value,

		plr.Values.SpecialCritDamage.Value,

		plr.Values.NumberOfAbnormalStats.Value,

		plr.Values.NumOfKicks.Value,

		plr.Values.SwingSpecial,

		plr.Values.StunSpecial,

		plr.Values.Level.Value
	}

	local success, errormessage = pcall(function()
		clientDataStore:SetAsync(playerUserId, data)
	end)

	if success then
		print("data successfully saved for "..playerUserId)
	else
		print("error saving data for "..playerUserId)
	end
end

game:GetService("Players").PlayerRemoving:Connect(saveData)

Nope. The player data is still not being saved. It gives me the same error message I implemented when it fails saving. “error saving data for (my userid)”

Are you in studio? If so, turn on studio access to api services in the settings menu. It should be located under the security tab. If not enabled, data stores will not function outside of the real game.

It is already on.
image
I am also using game.Players.LocalPlayer:Kick() so my datastore has time to process.

As I said in the post, my problem isnt the script kinda… it just seems datastore has a “capacity” that I have no idea if im past or not. The values I made shouldnt be more than 4MB.

Why are you using plr.CharacterAdded()? You dont need that for the DataStore to work.

Right. I used to save datastore inside of character.I changed it to player. Forgot i left that in

You can only use game.Players.LocalPlayer on the Client, not the Server. Are you storing your data for each player on the Client? Make sure to save and load data on the Server

Its a severscript in SeverScriptService. Also, when did I use game.Players.LocalPlayer

Like where’s the bit with the game.Players.LocalPlayer:Kick()? You can’t do that on the server, as I stated before, you can only do that on the Client. I’m taking about the part above when someone asked is “Enable access to studio api services” on

Oh. I use game.Players.LocalPlayer:Kick inside of roblox studio command bar

Also, is it just me, or are you going completely off-topic? the problem is my datastore isnt saving. Not that I cant kick someone on a serverscript even though I wasnt using a server script to kick the player