So I managed to create a script (with help from the replies):
local gui = script.Parent.Parent.StarterGui.GUI.Frame
local DataStoreService = game:GetService("DataStoreService")
local color3 = gui.BackgroundColor3
local DataStore = DataStoreService:GetDataStore("DataStore")
local function convertColor3ToTable(color3)
return {
["R"] = color3.R,
["G"] = color3.G,
["B"] = color3.B,
}
end
local success, whoops = pcall(function()
DataStore:GetAsync(convertColor3ToTable(color3) )
end)
if success then
DataStore:UpdateAsync(convertColor3ToTable(color3) )
print("Colors have been saved!")
else
warn("An error occurred:", whoops)
end
But there is a problem:
There’s some problem with line 20.
Try this instead,
local gui = script.Parent.Parent.StarterGui.TheWholePC.Frame
local DataStoreService = game:GetService("DataStoreService")
local color3 = gui.BackgroundColor3
local DataStore = DataStoreService:GetDataStore("DataStore")
local function convertColor3ToTable(color3)
return {
["R"] = color3.R,
["G"] = color3.G,
["B"] = color3.B,
}
end
local data
local success, whoops = pcall(function()
data = DataStore:GetAsync("BgColor-")
end)
if success then
local savedColor = data
DataStore:SetAsync("BgColor-", convertColor3ToTable(color3))
print("Colors have been saved!")
else
warn("An error occurred:", whoops)
end
It is still not working despite the output saying the success message.
It should be, it is, right now saving the data, it’s just it’s not loading any new data. I didn’t know if you wanted to load a colour so I just made a variable for savedColor if you wanted to change it.
1 Like
Ohhh. So the color is saved to the datastore but it just doesn’t load? Now how do I load it?
local gui = script.Parent.Parent.StarterGui.TheWholePC.Frame
local DataStoreService = game:GetService("DataStoreService")
local color3 = gui.BackgroundColor3
local DataStore = DataStoreService:GetDataStore("DataStore")
local function convertColor3ToTable(color3_)
return {
["R"] = color3_.R,
["G"] = color3_.G,
["B"] = color3_.B,
}
end
local data
local success, whoops = pcall(function()
data = DataStore:GetAsync("BgColor-")
end)
if success then
local savedColor = data
gui.BackgroundColor3 = savedColor
DataStore:SetAsync("BgColor-", convertColor3ToTable(color3))
print("Colors have been saved!")
else
warn("An error occurred:", whoops)
end