DataStore not saving my data table

  1. What do you want to achieve? Keep it simple and clear!

  2. What is the issue? Include screenshots / videos if possible!

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

Lately I have been working for creating a paiting game.
Player’s data table not saving in datastore, I can not find out what the problem is.
sorry for my bad English :<


game.Players.PlayerRemoving:Connect(function(plr)
	local success, errorMsg

	success, errorMsg = pcall(function()
		local savedata = DataModule.GetData(plr)
		print(savedata)
		DataStore:SetAsync(plr.UserId,savedata)
	end)

	if success then
		print("successfully saved "..plr.Name.."'s Data")
	else
		print(errorMsg)
	end
end)

saving output

loading output
image

Try:

	DS:UpdateAsync(key1, function(someTable)
		someTable = someTable or {} --someTable might be nil
		someTable = {"Value1", "Value2"}
		return someTable
	end)

still doesnt work :frowning_face:

image

You are trying to store just strings and numbers right?

1 Like

Can I see the full script before I can try to solve your problem?

This table has table and string
DataTable={
[1] = Table,
[“Key”] = “Userid”,
}

This is the all program


local Players = game.Players
local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("PlayerData")
local RemoteEvent = game.ReplicatedStorage:FindFirstChild("RemoteEvents"):FindFirstChild("SaveImage")
local RemoteEvent2 = game.ReplicatedStorage:WaitForChild("RemoteEvents"):FindFirstChild("SaveVideo")
local RemoteEvent3 = game.ReplicatedStorage:WaitForChild("RemoteEvents"):FindFirstChild("GetVideo")
local DataModule = require(game.ServerScriptService.DataModule)
--[[

Tableの内部構造

{
		
	{R,G,B}
	{R,G,B}
	{R,G,B}
	   .
	   .
	   .
	   
}

--]]

local function LoadImageFromData(plr,ImageData,val)
	local frames = plr:WaitForChild("PlayerGui"):FindFirstChild("Home").Save.inside
	local frames2 = plr:WaitForChild("PlayerGui"):FindFirstChild("Home").List.inside
	for i,v in pairs(ImageData) do
		frames["Frame"..val]:FindFirstChild("G-"..i).BackgroundColor3 = Color3.fromRGB(v[1]*255,v[2]*255,v[3]*255)
		frames2["Frame"..val]:FindFirstChild("G-"..i).BackgroundColor3 = Color3.fromRGB(v[1]*255,v[2]*255,v[3]*255)
	end
end

RemoteEvent2.OnServerEvent:Connect(function(plr,data,key,speed,title,frames)
	DataModule.SaveData(plr,data,key,speed,title,frames)
end)

Players.PlayerAdded:Connect(function(plr)
	
	--プレイヤーの中にグリッドをコピーする--
	for i=1, 3, 1 do
	local frames = plr:WaitForChild("PlayerGui"):WaitForChild("Home").Save.inside
	local G = game.ReplicatedStorage.G
	local F1 = frames:FindFirstChild("Frame"..i)
	local n = 1

	for x = 0 , 31 , 1 do
		for y = 0 , 31 , 1 do
			local CloneG = G:Clone()
			CloneG.Name = "G-"..n
			CloneG.Parent = F1
			CloneG.Size = UDim2.new(0.03125,0,0.03125,0)
			CloneG.Position = UDim2.new(0.03125*y,0,0.03125*x,0)
			n = n + 1
			end
		end
	end
	
	--プレイヤーの中にグリッドをコピーする2--
	for i=1, 3, 1 do
		local frames = plr:WaitForChild("PlayerGui"):WaitForChild("Home").List.inside
		local G = game.ReplicatedStorage.G
		local F1 = frames:FindFirstChild("Frame"..i)
		local n = 1

		for x = 0 , 31 , 1 do
			for y = 0 , 31 , 1 do
				local CloneG = G:Clone()
				CloneG.Name = "G-"..n
				CloneG.Parent = F1
				CloneG.Size = UDim2.new(0.03125,0,0.03125,0)
				CloneG.Position = UDim2.new(0.03125*y,0,0.03125*x,0)
				n = n + 1
			end
		end
	end
	
	--データをロードする--
	
	local success,err
	local Data = {}
	local frames = plr:WaitForChild("PlayerGui"):WaitForChild("Home").Save.inside

	success,err = pcall(function()
		Data = DataStore:GetAsync(plr.UserId)
		print(Data)
	end)

	if success then
		if Data then
			for i,v in pairs(Data) do
				local key = v["key"]
				local speed = v["SP"]
				local title = v["TT"]
				local frames = v["FR"]
				if v and speed and title and frames then
				LoadImageFromData(plr,v[1],i)
					DataModule.SaveData(plr,v,key,speed,title,frames)
				end
			end
		else

		end
	else
		--plr:Kick("Something went wrong, Please rejoin later.")
	end
	
	
end)

RemoteEvent.OnServerEvent:Connect(function(plr,data,val)
	LoadImageFromData(plr,data,val)
end)

RemoteEvent3.OnServerEvent:Connect(function(plr,val)
	local data = DataModule.GetData(plr,val)
	
	if data then
		local speed = data["SP"]
		local frame = data["FR"]
		RemoteEvent3:FireClient(plr,data,speed,frame)
	end
end)

game.Players.PlayerRemoving:Connect(function(plr)
	local success, errorMsg

	success, errorMsg = pcall(function()
		local newdata = DataModule.GetData(plr)
		DataStore:UpdateAsync(plr.UserId, function(someTable)
			local savedata = newdata
			return savedata
		end)
	end)

	if success then
		print("successfully saved "..plr.Name.."'s Data")
	else
		print(errorMsg)
	end
end)

Oops, I was forgetting Datastore does not save intvalue, I got to use tostring()

1 Like

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