Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I save a color3 value through a database?

Asked by 4 years ago
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

Log in to vote
2
Answered by 4 years ago

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

Ad

Answer this question