Colors saving incorrectly when using Data Stores

I made a system where it updates a certain Color3 value in a folder when a remote event is fired. When I attempt to retrieve that value that I save in a dictionary, the numbers are essentially negatively exponentially multiplied.


That is a screenshot of the code that fires a remote event to update the folder


This is a screenshot of the code that receives the event and updates the folder accordingly (ignore the abbreviations I use for the variables). All values in the folder seem to be found, as no error is thrown when initializing the script.


This is a screenshot of one of the values that are saved in the DataStore.


This code updates the folder when you join to match the preferences that were retrieved by the DataStore service

Screenshot 2024-10-31 at 12.11.28 AM
And yet, this is what is printed when the ColorValue is printed.

Please help me! I have been stuck on this for days now, and I really want to release this feature to my game for better customization.

When you use Color3.fromRGB() it converts into a Color3 value, which is between 0 and 1. Then when you are setting it via your loop using Color3.fromRGB, you are technically setting the “G” value to 1, which then becomes .003921 and is the wrong color.

You can multiply your R, G, B values by 255 when setting the value under your RetrievedPlayerData.Colors loop and it should be fixed, alternatively, you could just use Color3.new() and put your RGB values in there too(which is simpler than multiplying by 255 for each number).

Replace the code in your 4th image with this:

if RetrievedPlayerData.Colors then
	for ColorName, ColorValue in pairs(RetrievedPlayerData.Colors) do
		print(ColorName, ColorValue)
		ColorPreferencesFolder[ColorName].Value = Color3.new(ColorValue["R"], ColorValue["G"], ColorValue["B"])
	end
end

That’s one solution, the other is to just have them send in the RGB values and save the whole numbers if you want to make it easier to read the RGB values in the datastore.

This worked! Thank you so much for teaching me a new concept of the RGB coding Roblox uses!

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