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

How do I save a color3 value through a database?

local DataStore = game:GetService("DataStoreService")
local ds = DataStore:GetDataStore("MoneySaveSystem")

game.Players.PlayerAdded:connect(function(player)
	local SkinColor = player:WaitForChild("Data").SkinColor
	SkinColor.Value = ds:GetAsync(player.UserId)
	SkinColor.Changed:connect(function()
	ds:SetAsync(player.UserId, SkinColor.Value)
		
	end)
end)

game.Players.PlayerRemoving:connect(function(player)
	ds:SetAsync(player.UserId, player.SkinColor.Value)
end)

Im trying to change the skincolor (from a value) for a character but it doesn't seem to work

1 answer

you would need to save 3 seperate values in a table, here's how:

local DataStore = game:GetService("DataStoreService")
local ds = DataStore:GetDataStore("MoneySaveSystem")

game.Players.PlayerAdded:connect(function(player)
    local SkinColor = player:WaitForChild("Data").SkinColor
    local Data = ds:GetAsync(player.UserId)
    if Data then
   	 SkinColor.Value = Color3.fromRGB(Data[1],Data[2],Data[3])
    else
         SkinColor.Value = Color3.fromRGB(255,255,255) --White
    end
    SkinColor.Changed:connect(function()
        ds:SetAsync(player.UserId, {SkinColor.Value.r,SkinColor.Value.g,SkinColor.Value.b})

    end)
end)

game.Players.PlayerRemoving:connect(function(player)
    ds:SetAsync(player.UserId, {SkinColor.Value.r,SkinColor.Value.g,SkinColor.Value.b})
end)

Hopefully This Helps

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