Datastore doesn't save

I want to save a table into my datastore then when I join back it prints the first value of the saved table

I get a warning on my output, the data doesn’t save when I leave

--Services 
local Players = game:GetService("Players")
local dss = game:GetService("DataStoreService")

--Variables 
local playerData = dss:GetDataStore("playerData")
local coolfolder = game.Workspace:WaitForChild("CoolFolder")

local saveTab = {}


local function makeTab(folder)
	for i,v in pairs(folder:GetChildren()) do 
		local intValue = Instance.new("IntValue")
		intValue.Name = v.Name..i
		table.insert(saveTab, intValue)
	end
end

makeTab(coolfolder)

print(saveTab[1].Name)


local function playerAdded(player)
	local userId = player.UserId 
	local success, response = pcall(function()
		return playerData:GetAsync(userId)
	end)
	if success then 
		print("ya")
	end
	if not response then 
		print("new player")
	else 
		print(response[1].Name)
	end
end

local function playerRemoved(player)
	local userId = player.UserId 
	local success, response = pcall(function()
		playerData:SetAsync(userId, saveTab)
	end)
	
	if success then 
		print("Data saved successfully")
	else 
		warn("Data didn't save")
	end
	
end


--Events 
Players.PlayerAdded:Connect(playerAdded)
Players.PlayerRemoving:Connect(playerRemoved)
1 Like

Its likely you don’t have studio access to api services enabled, turn that on in game settings.

1 Like

What is the warning? Is it just "Data didn't save" or is it something else?

1 Like

yeah its just data didn’t save

try this:

local success, response = pcall(function()
		playerData:SetAsync(userId, saveTab)
	end)
	
	if success then 
		print("Data saved successfully")
	else 
		warn("Data didn't save", response)
	end

You can then find the error code and what is causing it with https://developer.roblox.com/en-us/articles/Datastore-Errors

1 Like

thanks i had this and I fixed it

DataStore does not store Objects (in this case IntValue), as it only supports UTF-8 characters.

1 Like

so I’m guessing they only store strings?

Yes, but not limited to strings. You can store numbers and tables too.

1 Like