Trying to finish up a save system

So, I am working with datastores right now for the first time ever, and I am quite happy with my progress so far, even if I am not doing things in the most optimal way yet, as far as I know. However, I am having one issue. Saving and loading everything is working so far, except for one Color3 variable. I’ll show you my code, in case there are other issues that I should correct, and also for help with a solution to this issue.

-- Leaderstats and Save File --
local Players = game:GetService("Players")
local datastoreservice = game:GetService("DataStoreService")

local database = datastoreservice:GetDataStore("AC")


-- Leaderboard Stats Manager --
function PlayerAdded(p)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	
	local Coins = Instance.new("IntValue")
	Coins.Name = "Coins"
	Coins.Parent = leaderstats
	
	local Prestige = Instance.new("IntValue")
	Prestige.Value = 1
	Prestige.Name = "Prestige"
	Prestige.Parent = leaderstats
	
	local generalSaveData = Instance.new("Folder")
	generalSaveData.Name = "generalsavedata"
	generalSaveData.Parent = p
	
	local Multiplier = Instance.new("IntValue")
	Multiplier.Value = 1
	Multiplier.Name = "Multiplier"
	Multiplier.Parent = generalSaveData
	
	local MultCost = Instance.new("IntValue")
	MultCost.Name = "MultCost"
	MultCost.Value = 10
	MultCost.Parent = generalSaveData
	
	local PrestCost = Instance.new("IntValue")
	PrestCost.Name = "PrestCost"
	PrestCost.Value = 2
	PrestCost.Parent = generalSaveData
	
	local coinColor = Instance.new("Color3Value")
	coinColor.Name = "coinColor"
	coinColor.Value = Color3.new(255, 255, 0)
	coinColor.Parent = generalSaveData
	
	leaderstats.Parent = p -- Parenting it last to make sure that all stats are parented correctly before references to
	-- leaderstats can be used
	
	
	
	-- Save Data Manager --
	
	local saveData = database:GetAsync(p.UserId)
	
	if saveData then
		
		print("Found data for player ", p)
		
		p:WaitForChild("leaderstats").Coins.Value = saveData[1]
		p:WaitForChild("leaderstats").Prestige.Value = saveData[2]
		p:WaitForChild("generalsavedata").Multiplier.Value = saveData[3]
		p:WaitForChild("generalsavedata").MultCost.Value = saveData[4]
		p:WaitForChild("generalsavedata").PrestCost.Value = saveData[5]
		--p:WaitForChild("generalsavedata").coinColor.Value = saveData[6]
		
		print(saveData)
		
	else
		
		print("Player has no save data")
		
		database:SetAsync(p.UserId, 0)
		
		print("Save Data created for ", p)
		
	end
end

function PlayerLeaving(player)
	
	local tableToSave = {
		player.leaderstats.Coins.Value,
		player.leaderstats.Prestige.Value,
		player.generalsavedata.Multiplier.Value,
		player.generalsavedata.MultCost.Value,
		player.generalsavedata.PrestCost.Value
		--player.generalsavedata.coinColor.Value
	}
	
	database:SetAsync(player.UserId, tableToSave)
	
	
	print("Data saved for player ", player)
end

Players.PlayerRemoving:Connect(PlayerLeaving)
Players.PlayerAdded:Connect(PlayerAdded)

I commented out the two lines of code that are causing errors, being

p:WaitForChild("generalsavedata").coinColor.Value = saveData[6]

And also

player.generalsavedata.coinColor.Value

When commenting this out, the saving system is working flawlessly.

Are you trying to save a ColorRGB value directly? Roblox DataStores support basic types like numbers, strings, and tables. You should convert the Color3 to a serializable format (like a table of RGB values) before saving and convert it back when loading.

1 Like
	local coinColorRGB = Color3.new(player.generalsavedata.coinColor.Value)
	
	local tableToSave = {
		player.leaderstats.Coins.Value,
		player.leaderstats.Prestige.Value,
		player.generalsavedata.Multiplier.Value,
		player.generalsavedata.MultCost.Value,
		player.generalsavedata.PrestCost.Value,
		coinColorRGB
	}

Ended up trying something like this, which gave me the error
“Data stores can only accept valid UTF-8 characters.”

You cannot save Colors directly, instead make a table of R,G,B and save it.

1 Like

Was hoping I wouldnt have to, but thank you, I will get on this and let you all know if it works

1 Like

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