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

0

Where is the error located?

0

line 16 and line 08

0

Try separating out the values so that there are 3 values representing R,G and B instead of a single Color3.

0

example?

1

{color3.r,color3.g,color3.b}

1

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.

1

Raw color3 data cannot be saved into DataStore - You'd have to convert it into a string or integer.