Saving an RGB Color to a DataStore

I’m trying to save an RGB color to a datastore to allow players in my game to customize the color of their overhead nametag. I’ve found multiple articles on this and tried their solutions but haven’t seemed to get them to work. How my script should work is it gets the RGB Color value of a GUI frame which is the color the player selected and then fires it to the server through a RemoteEvent to save it to the datastore.

Anyone know how to do this? I’m really struggling and would appreciate any help.

Get the rgb color and save it in a tsble

local Color = {R = color.R, G = color.G, B = color.B}

Havent tested

3 Likes

Would I do this from the LocalScript or Script? When I try to fire the BackgroundColor3 property in the parameters through the RemoteEvent to the server, it says ‘Attempt to index nil with R’

Yeah, havent tested it. But you’d do something similar to it. Also you do it on the server script or on the client, just send it to the data store

1 Like

Actually, according to the wiki it should work, try checking if the background color is nil

Error:

Server Script:

local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("NameColor")

local function saveData(Player, Data)
	local DataToSave = Data
	local success, err = pcall(function()
		DataStore:SetAsync(Player.UserId, DataToSave)
	end)

	if success then
		print("Data has been saved!")
		print(DataToSave)
	else
		print("Data hasn't been saved!")
		warn(err)		
	end
end

game.ReplicatedStorage.SaveNameColor.OnServerEvent:Connect(function(Player, NameColor)
	saveData(Player, NameColor)
end)

Local Script:

NameTagColor:WaitForChild("Buy"):WaitForChild("Button").MouseButton1Click:Connect(function()

local NameColor = ColorDisplay

local DataTable = {R = ColorDisplay.BackgroundColor3.R, G = ColorDisplay.BackgroundColor3.G, B = ColorDisplay.BackgroundColor3.B}

game.ReplicatedStorage.SaveNameColor:FireServer(Player, DataTable)

end)

Edit: Wait, I think I’m doing something wrong with the parameters

Print the data table in both the server script and local script. Tell me the results

You have to save it as a table!

Turns out I was doing the parameters wrong, it saves and prints something but it’s really weird and not what I want…

Is local DataTable = {R = ColorDisplay.BackgroundColor3.R, G = ColorDisplay.BackgroundColor3.G, B = ColorDisplay.BackgroundColor3.B} a table, or am I dumb…?

1 Like

You can just put the color into a Color3Value, then save the Color3Value. When you need it, take the value from the DataStore, and put it in the Color3Value! :smiley_cat:

Wait go to the 3 dots on the output and turn off logging, it should fix it and then print again

How would I do this? :sob: charsssss

Hmm, I would skip the {R =, G =, B =}, it creates unnecessary data, just instead remember Table[1] is R, Table[2] is G, and Table[3] is B. That is a table though

1 Like

Also the print weird thing is normal.

1 Like

Isn’t that what my code already did?

1 Like

Still printing the same thing… weird

Its normal, the code saved fine.

OH, how would I retrieve it when the player joins? Thanks :heart:

just do table[1], table[2], table[3]. Another way is just saving the hexadecimal representation of the color3 as a string