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 5 years ago
01local DataStore = game:GetService("DataStoreService")
02local ds = DataStore:GetDataStore("MoneySaveSystem")
03 
04game.Players.PlayerAdded:connect(function(player)
05    local SkinColor = player:WaitForChild("Data").SkinColor
06    SkinColor.Value = ds:GetAsync(player.UserId)
07    SkinColor.Changed:connect(function()
08    ds:SetAsync(player.UserId, SkinColor.Value)
09 
10    end)
11end)
12 
13game.Players.PlayerRemoving:connect(function(player)
14    ds:SetAsync(player.UserId, player.SkinColor.Value)
15end)

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 5 years ago

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

01local DataStore = game:GetService("DataStoreService")
02local ds = DataStore:GetDataStore("MoneySaveSystem")
03 
04game.Players.PlayerAdded:connect(function(player)
05    local SkinColor = player:WaitForChild("Data").SkinColor
06    local Data = ds:GetAsync(player.UserId)
07    if Data then
08     SkinColor.Value = Color3.fromRGB(Data[1],Data[2],Data[3])
09    else
10         SkinColor.Value = Color3.fromRGB(255,255,255) --White
11    end
12    SkinColor.Changed:connect(function()
13        ds:SetAsync(player.UserId, {SkinColor.Value.r,SkinColor.Value.g,SkinColor.Value.b})
14 
15    end)
16end)
17 
18game.Players.PlayerRemoving:connect(function(player)
19    ds:SetAsync(player.UserId, {SkinColor.Value.r,SkinColor.Value.g,SkinColor.Value.b})
20end)

Hopefully This Helps

Ad

Answer this question