Datastore not saving OR loading

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I would like to be able to save the ColoreAvatar | NomeAvatar | IntroDone. And then load them when the player joins back.

  2. What is the issue? Include screenshots / videos if possible!
    I get no error from the script, but when i rejoin the game the data aren’t shown, and if i use the print() command to see what’s inside of the ColoreAvatar it tells, nil.

--Variables
local DataStoreService = game:GetService("DataStoreService")
local MyDataStore = DataStoreService:GetDataStore("MyDataStore")
local Players = game:GetService("Players")

--Function when the player joins or reset
local function onPlayerAdded(player)

	--Data Register
	local ColoreAvatar = MyDataStore:GetAsync(player.UserId.. "-ColoreAvatar")
	local NomeAvatar = MyDataStore:GetAsync(player.UserId.. "-NomeAvatar")
	local IntroDone = MyDataStore:GetAsync(player.UserId.. "-IntroDone")

	--Creates Data Workspace
	local DataWorkspace = game.Workspace.Date.Examples.PlayerInfo:Clone()
	DataWorkspace.Name = "=".. player.Name
	DataWorkspace.Parent = game.Workspace.Date.Giocatori

	--Getting Data
	if ColoreAvatar ~= nil then
		DataWorkspace:SetAttribute("Colore",ColoreAvatar)
	end
	if NomeAvatar ~= nil then
		DataWorkspace:SetAttribute("Nome",NomeAvatar)
	end
	if IntroDone ~= nil then
		DataWorkspace:SetAttribute("Intro",IntroDone)
	end

end

--Function when the player leaves the game
local function onPlayerRemoved(player)

	--Getting Variables
	local Folder = game.Workspace.Date.Giocatori:FindFirstChild("=" ..player.Name)
	local Nome = Folder:GetAttribute("Nome")
	local Color = Folder:GetAttribute("Colore")
	local Intro = Folder:GetAttribute("Intro")

	--Save Data
	MyDataStore:GetAsync(player.UserId.. "-ColoreAvatar", Color)
	MyDataStore:GetAsync(player.UserId.. "-NomeAvatar", Nome)
	MyDataStore:GetAsync(player.UserId.. "-IntroDone", Intro)
end

--Start functions
Players.PlayerAdded:Connect(onPlayerAdded)
Players.PlayerRemoving:Connect(onPlayerRemoved)

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I tried looking around, found nothing.

you didn’t pcall() the set/getasync functions, thats why you have no error

How to use it?
Where should I add it?
@Mister33j

example of a pcall in you’r(e) getasync function

local s, err = pcall(function()
    local ColoreAvatar = MyDataStore:GetAsync(player.UserId.. "-ColoreAvatar")
	local NomeAvatar = MyDataStore:GetAsync(player.UserId.. "-NomeAvatar")
	local IntroDone = MyDataStore:GetAsync(player.UserId.. "-IntroDone")
end)

if s then -- s(sucess) is true then
 print("data sucessfully collected")
else
 warn(err) -- error message
end

By adding this it doesn’t let me use the ColoreAvatar | NomeAvatar | IntroDone Variable to get data after.
@Mister33j

that shouldn’t happen lol, is there an 5__ error message?

is studio api services on?

@Mister33j
The service is on,
The variable are underlined after

i forgor something lol

local ColoreAvatar
local NomeAvatar
local IntroDone

local s, err = pcall(function()
    ColoreAvatar = MyDataStore:GetAsync(player.UserId.. "-ColoreAvatar")
	NomeAvatar = MyDataStore:GetAsync(player.UserId.. "-NomeAvatar")
	IntroDone = MyDataStore:GetAsync(player.UserId.. "-IntroDone")
end)

if s then -- s(sucess) is true then
 print("data sucessfully collected")
else
 warn(err) -- error message
end

The code doesn’t give me errors anymore, tho it seems like the data are not there?
Cause if i print print(ColoreAvatar) out after i have left and rejoined it tells me nil
@Mister33j

""

did you mean SetAsync?

1 Like

@Mister33j
SetAsync is to save the data?
I replaced the GetAsync in the save data but it shows this error: 104: Cannot store Color3 in data store. Data stores can only accept valid UTF-8 characters.

||Sorry for annoying you so much||

revert that

you cannot save a Color3 value in DataStore, it means

why am i being forced to do this myself lol, other people aern’t also responding, im not that good at datastores

xD don’t feel forced to help.
Idk how to save the colors now btw, Should i save them as: Red, Blue, Green

1 Like

save it as a table {255, 255, 255}
i remember i did a storage system with table data stores

1 Like

Still not saving any data, not only the color. But neither the name and the intro bool.
Imma send the script after the various changes we did.
The print is to check if they got saved since they didn’t got updated in the Attribute, and the table was always {1,1,1}

--Variables
local DataStoreService = game:GetService("DataStoreService")
local MyDataStore = DataStoreService:GetDataStore("MyDataStore")
local Players = game:GetService("Players")

--Function when the player joins or reset
local function onPlayerAdded(player)
	
	--Data Variable
	local ColoreAvatar = {}
	local Colore
	local NomeAvatar
	local IntroDone
	
	--Data Register
	local s, err = pcall(function()
	 	ColoreAvatar = MyDataStore:GetAsync(player.UserId.. "-ColoreAvatar")
		NomeAvatar = MyDataStore:GetAsync(player.UserId.. "-NomeAvatar")
		IntroDone = MyDataStore:GetAsync(player.UserId.. "-IntroDone")
	end)
	if s then -- s(sucess) is true then
		print("data sucessfully collected")
	else
		warn(err)-- error message
	end
	
	print(ColoreAvatar)
	
	--Creates Data Workspace
	local DataWorkspace = game.Workspace.Date.Examples.PlayerInfo:Clone()
	DataWorkspace.Name = "=".. player.Name
	DataWorkspace.Parent = game.Workspace.Date.Giocatori

	--Getting Data
	if ColoreAvatar ~= nil then
		Colore = Color3.new(ColoreAvatar[1], ColoreAvatar[2], ColoreAvatar[3])
		DataWorkspace:SetAttribute("Colore",Colore)
	end
	if NomeAvatar ~= nil then
		DataWorkspace:SetAttribute("Nome",NomeAvatar)
	end
	if IntroDone ~= nil then
		DataWorkspace:SetAttribute("Intro",IntroDone)
	end

end

--Function when the player leaves the game
local function onPlayerRemoved(player)

	--Getting Variables
	local Folder = game.Workspace.Date.Giocatori:FindFirstChild("=" ..player.Name)
	local Nome = Folder:GetAttribute("Nome")
	local Color = Folder:GetAttribute("Colore")
	local Intro = Folder:GetAttribute("Intro")
	
	local ColoreAvatar = {Color.R, Color.G, Color.B}

	--Save Data
	MyDataStore:SetAsync(player.UserId.. "-ColoreAvatar", ColoreAvatar)
	MyDataStore:SetAsync(player.UserId.. "-NomeAvatar", Nome)
	MyDataStore:SetAsync(player.UserId.. "-IntroDone", Intro)
end

--Start functions
Players.PlayerAdded:Connect(onPlayerAdded)
Players.PlayerRemoving:Connect(onPlayerRemoved)