Trying to save a colo

HI, I need help with this script, i need to save the color of a block, the Value inside the cube is a brick color value

local DataStoreService = game:GetService(“DataStoreService”)

local myDataStore = DataStoreService:GetDataStore(“myDataStore”)

game.Players.PlayerAdded:Connect(function(player)
local color = workspace.CUBE.Value
local data
local succes, errormessage = pcall(function()
data = myDataStore:GetAsync(player.UserId…“-color”)
end)
if succes then
color.Value = data
else
print(“mmm no”)
warn(errormessage)
end
end)

game.Players.PlayerRemoving:Connect(function(player)
local succes, errormessage = pcall(function()
myDataStore:SetAsync(player.UserId…“-color”,workspace.CUBE.Value.Value)
end)

if succes then
    print("Done boy")
else
    print("MMM no")
    warn(errormessage)
end

end)

What exactly is this line? A BrickColor value?

Colors cannot directly be store into a datastore, you have to store the 3 color properties into a table, save that, and then put those back as a color and then it should work

local DataStoreService = game:GetService("DataStoreService")

local myDataStore = DataStoreService:GetDataStore("myDataStore")

game.Players.PlayerAdded:Connect(function(player)
	local color = workspace.CUBE.Value
	local data
	local succes, errormessage = pcall(function()
		data = myDataStore:GetAsync(player.UserId.."-color")
	end)
	if succes then
		color.Value = Color3.fromRGB(data[1],data[2],data[3])
	else
		print("mmm no")
		warn(errormessage)
	end
end)

game.Players.PlayerRemoving:Connect(function(player)
	local color = workspace.CUBE.Value.Value
	local succes, errormessage = pcall(function()
	myDataStore:SetAsync(player.UserId.."-color",{color.R,color.G,color.B})
	end)

	if succes then
		print("Done boy")
	else
		print("MMM no")
		warn(errormessage)
	end
end)
2 Likes

I used a brick color value like this
image

Just convert it to a string using the tostring function, Colors can’t be saved in DataStores however you can workaround this

Also you referenced CUBE.Value.Value twice

myDataStore:SetAsync(player.UserId…"-color",tostring(workspace.CUBE.Value))

Sorry I´m not good at this i tought i was going to use it

Cube is not the name of the value, cube is the names of the part
image

Ok that makes it even more confusing

myDataStore:SetAsync(player.UserId…"-color",tostring(workspace.CUBE.Value.Value))

Just do that then, and when a succes has been detected:

color.Value = BrickColor.new(data)
1 Like