Datastore refusing to save items ingame but not in studio

I made a item saving system for my game a few days ago, ive recently noticed this bug where items dont save if you are ingame, but they somehow save inside studio?

Code
local function saveData(player) 
	local tableToSave = {
		player.Data.Strength.Value;
		player.Data.Speed.Value,
		player.Data.InCombat.Value,
		player.Data.SkinColor.Value,
		player.Data.Strength.Value,
		player.Data.New.Value,
		player.Data.Lives.Value,
        player.Data.Armor.Value,
        player.Data.Face.Value,
        player.Data.Traits.Value,
        player.Data.LastPosition.Value,
 player.Data.HairColor.Value,
player.Data.Hair.Value,
player.Data.Weapon.Value,
player.Data.WeaponXp.Value,
	}

for i,v in pairs(player.Backpack:GetChildren()) do
table.insert(tableToSave, v.Name)
end



local success, err = pcall(function()
		datastore:SetAsync(player.UserId, tableToSave) 

	end)

	if success then 

	else 
		warn(err)		
	end
end
PlayerRemoving
game.Players.PlayerRemoving:Connect(function(player)
	local success, err  = pcall(function()
		saveData(player)
	end)

	if success then
		warn(player.Name.."'s Data has been saved.. ID"..player.userId)
	else
		warn(player.Name.."'s Data has not been saved!.. ID"..player.userId)
	end
end)

game:BindToClose(function()
	for _, player in pairs(game.Players:GetPlayers()) do 
		local success, err  = pcall(function()
			saveData(player)
		end)

		if success then
			warn(player.Name.."'s Data has been saved.. ID"..player.userId)
		else
			warn(player.Name.."'s Data has not been saved!.. ID"..player.userId)
			warn(err)
		end
	end
	end)
Load Tools
for i,v in pairs(data) do

if Items:FindFirstChild(v) and InCombat.Value == false then

Items[v]:Clone().Parent = player.Backpack


end

end

i dont know why this happens, if somebody knows how to fix this, please tell me as this is making me pretty desperate.

Edit: now it doesnt want to save in studio either

Edit #2: i worked out a temporal fix that might cause data issues, im still waiting for someone to give me a possible solution

This is likely to be a server issue. Can you send the output from the game and in studio? (Say /console in chat to view this)

it doesnt error, the datastore and other things work fine, the only thing that refuses to work is the item saving.

Edit: plus its not client sided

DataStores are made to save string or integer values. It will not save a table value.

You can use table.concat(Table, Separator) to turn an entire table into 1 string

You can use string.Split(String, Separator) to turn a string into a table.

Care to show me how to do it, i currently dont have access to my pc and such.

Before saving ‘TableToSave’ do this:

TableToSave = table.concat(TableToSave,";Split;")

After you get the data from the store do this:

Table = string.split(Data,";Split;")

Quite simple to learn and once you learn it it has a lot of uses.

Thanks alot, ill try to use this method once i get access to my pc.

i dont quite understand image

i think i fixed it by turning the tool’s name into a string, is that a viable option aswell?

You want to save string.
DSS(DataStoreService) Is intended to save string.

I will break it down so everyone can fully understand what you can really do with DSS.
It can be used for much more than just player data.

-- This is the DSS service that allows access to the stores.
local DSS = game:GetService("DataStoreService")

-- Gets The Store With The String 'Player Experience
-- This Can Be Any String And The String Can Even Be Created
local XP = DSS:GetDataStore("PlayerExperience")

-- This Will Assign Data To The String, The String Can Be Anything
-- People Often Mistake DSS For Saving Player Data
-- However It Saves To A String Not The Player
XP:SetAsync("Player_1234", 50)

The Key To Remember Is that DataStores can save string or integers upto 250,000 Kb. I find it easier to use them when I think of DSS as a sort of folder system.
StoreString.IdentifyingString → Access To The Saved Value

Many misunderstand the key fact that you can make your own strings and names and even store the names of stores in other stores. You can make an advanced network quickly once you understand this key fact and realise what you have overlooked.

The DSS limits can be bypassed by creating multiple save values. I’ve done this by using one store to store the name of another. Then every value in that second store has its identifying string set to a number. This means I can literally save lists and endless data that can be retried using for loops.

1 Like

There’s also another rule towards the DataStoreService on the engine side, the value has to a string, or something that can be stringified and that it can be strinified to a UTF-8 character.

With this, even though it looks like I am going to set this key name test as the integer 1, because it’s url encoded, it will become a string.

POST https://gamepersistence.roblox.com/persistence/set?key=test&type=standard&scope=global&target=test&valueLength=3
Accept: application/json
Cookie: .ROBLOSECURITY={{cookie}}
Accept-Encoding: gzip, deflate
Cache-Control: no-cache
Connection: close
Roblox-Place-Id: {{placeId}}
Content-Type: application/x-www-form-urlencoded

&value=123
HTTP/1.1 200 OK
cache-control: no-cache
pragma: no-cache
content-type: application/json; charset=utf-8
content-encoding: gzip
expires: -1
vary: Accept-Encoding
x-frame-options: SAMEORIGIN
roblox-machine-id: ...
x-powered-by: ASP.NET
p3p: ...
date: ...
content-length: 48
x-rblx-pop: ...

{
  "data": "123"
}
1 Like

I see, thats why it started working when i used tostring in the tool’s name, thanks alot

1 Like