Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How can I store color3 values in a datastore?

I know you have to do this as a table but when I tried this I couldn't get the DS to update it, I'm making a colour customizable system in my game that's supposed to save but when I made it in a table and did it so the parts in your player get the colorfromrgb it doesn't save in the table, I even added a color3value that isn't meant to be saved but just to be updated and if it gets changed then the script knows to setasync the table contents but that doesn't seem to do anything, the table just goes blank once my character respawns

Here's the code (I only did it with the lightcolour to test it, it prints "New Colour" in output but doesn't seem to actually save it even though it does print "Saved New Colour"):

local datastore = game:GetService("DataStoreService")
local ds2 = datastore:GetDataStore("LightSaveSystem")
local ds3 = datastore:GetDataStore("PrimarySaveSystem")
local ds4 = datastore:GetDataStore("SecondarySaveSystem")
local ds5 = datastore:GetDataStore("MasterSaveSystem")

game.Players.PlayerAdded:connect(function(plr)
 local folder = Instance.new("Folder", plr)
 folder.Name = "playerstats"
 
             
				
	local Light = Instance.new("LocalizationTable", folder)
	Light.Name = "Light"
	
	local LightColour = Color3.new(0/255, 255/255, 0/255)
	
	local LC = Instance.new("Color3Value", folder)
	LC.Name = "LightColourChange"
	
	local Light2 = {LightColour.R, LightColour.G, LightColour.B}
		
	local Primary = Instance.new("LocalizationTable", folder)
	Primary.Name = "Primary"
		
	local PrimaryColour = Color3.new(0/255,0/255,0/255)

	local PC = Instance.new("Color3Value", folder)
	PC.Name = "PrimaryColourChange"

	local Primary2 = {PrimaryColour.R, PrimaryColour.G, PrimaryColour.B}
		
	local Secondary = Instance.new("LocalizationTable", folder)
	Secondary.Name = "Secondary"
	
	local SecondaryColour = Color3.new(255/255,255/255,255/255)

	local SC = Instance.new("Color3Value", folder)
	SC.Name = "SecondaryColourChange"

	local Secondary2 = {SecondaryColour.R, SecondaryColour.G, SecondaryColour.B}

	local Master = Instance.new("BoolValue", folder)
	Master.Name = "Master"
	
	
	Light = ds2:GetAsync(plr.UserId)  or Light2
	ds2:SetAsync(plr.UserId, Light)
	
	
	Primary = ds3:GetAsync(plr.UserId) or Primary2
	ds3:SetAsync(plr.UserId, Primary)
	
	
	Secondary = ds4:GetAsync(plr.UserId)  or Secondary2
	ds4:SetAsync(plr.UserId, Secondary)


	Master.Value = ds5:GetAsync(plr.UserId) or false
	ds5:SetAsync(plr.UserId, Master.Value)

 
	LC.Changed:connect(function()
		print("New Colour")
		ds2:SetAsync(plr.UserId, Light)
		print("Saved New Colour")
 end)
 
 
	PC.Changed:connect(function()
		ds3:SetAsync(plr.UserId, Primary)
 end)
 
	SC.Changed:connect(function()
		ds4:SetAsync(plr.UserId, Secondary)
	end)

	Master.Changed:connect(function()
		ds5:SetAsync(plr.UserId, Master.Value)
	end)


end)

1 answer

Hey, I saw your other post but had decided you would've solved it by now, as the person who commented on your post said:

( this was posted before your edit, you should make values of the colors and save them into the datastore if your struggling with getting the R, G and B values of a Color3.new() )

You must use Tables to store individual values of color codes.

example:

DO NOT USE THIS, ITS AN EXAMPLE AND MAY HAVE ERRORS.

local DS = game:GetService'DataStoreService'
local STO = DS:GetDataStore'COLOURS'

game.Players.PlayerAdded:Connect(function(Player)
   local exist, noexist = pcall(function()
       local Table = STO:GetAsync(Player.UserId)
       local Color = Color3.fromRGB(Table[1], Table[2], Table[3])
   end)

   if not exist then
      STO:SetAsync(Player.UserId, {255,0,0})
   end
end)

some posts on devforum which may help:

https://devforum.roblox.com/t/how-to-save-brickcolors-or-color3-in-a-datastore/162030 https://devforum.roblox.com/t/how-to-save-color3-to-datastore/742283

2 comments

0

I don't understand any of this I've never used tables before so I don't know how to utilise this :(

0

Try making your values RAW instead of getting them from a Color3.new(), for example use {255, 0, 0} instead of {Color.R, Color.G, Color.B} - also you can try to make the Color3.new to Color3.fromRGB, that could possibly help.

This discussion is preserved as it was. New answers, comments, and votes are closed.