You can write your topic however you want, but you need to answer these questions:
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.
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)
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I tried looking around, found nothing.
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
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
@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.
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)