How can i fix this the code i have.
local ChatColor = Instance.new("Color3Value")
ChatColor.Name = "ChatColor"
ChatColor.Parent = leaderstats
local key = "user-" .. player.userId
local storeditems = datastore:GetAsync(key)
if storeditems then
ChatColor.Value = storeditems[1]
else
local items = {ChatColor.Value}
datastore:SetAsync(key, items)
end
end)
game.Players.PlayerRemoving:connect(function(player)
local items = { player.leaderstats1.ChatColor.Value}
local key = "user-" .. player.userId
datastore:SetAsync(key, items)
wait(3)
print(player.Name.."Left The Game")
end)
Full code
local datastore = game:GetService("DataStoreService"):GetDataStore("Color3Testing")
game.Players.PlayerAdded:connect(function(player)
local leaderstats = Instance.new("IntValue")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local ChatColor = Instance.new("Color3Value")
ChatColor.Name = "ChatColor"
ChatColor.Parent = leaderstats
local key = "user-" .. player.userId
local storeditems = datastore:GetAsync(key)
if storeditems then
ChatColor.Value = storeditems[1]
else
local items = {ChatColor.Value}
datastore:SetAsync(key, items)
end
end)
game.Players.PlayerRemoving:connect(function(player)
local items = { player.leaderstats1.ChatColor.Value}
local key = "user-" .. player.userId
datastore:SetAsync(key, items)
wait(3)
print(player.Name.."Left The Game")
end)

7 comments
Where is the error located?
line 16 and line 08
Try separating out the values so that there are 3 values representing R,G and B instead of a single Color3.
example?
{color3.r,color3.g,color3.b}
dataStores cannot save ROBLOX values such as Color3, BrickColor or Vector3. You must to conver them into single integrers and put them in an array, then save.
Raw color3 data cannot be saved into DataStore - You'd have to convert it into a string or integer.