I've asked many questions regarding this issue and havent gotten a valid answer yet. I know how to save and load with Datastore but don't know how you would save Color3 Values using JSON.
You can't technically "save a Color3" but you can save the RGB values. According to the Roblox wiki Color3s have three values... R G and B. R is red, G is green, B is blue.
To recreate a Color3 from it's red, green, and blue colors you can use Color3.fromRGB or Color3.new and divide your RGB values by 255 to get a decimal.
Wiki page: http://wiki.roblox.com/index.php?title=API:Color3
Example table to save:
1 | { R = color 3. R, G = color.G, B = color 3. B } |
You can save the RGB value simply with a datastore - I will reference this wiki throughout my explanation.
01 | --In a script in ServerScriptService. Data stores are SERVER ONLY! |
02 |
03 | local DataStoreService = game:GetService( "DataStoreService" ) |
04 | local RGBdata = DataStoreService:GetDataStore( "RGB" ) |
05 | local a = 5 -- Insert first RGB color |
06 | local b = 10 -- Insert second RGB color |
07 | local c = 50 -- Insert third RGB color |
08 | local savetable = { a, b, c } |
09 |
10 | local function onPlayerAdded(player) |
11 | local newdata = RGBdata:GetAsync(player) |
12 | --This is your RGB that you saved in the data store. |
13 | end |
14 |
15 | game.Players.PlayerAdded:Connect(onPlayerAdded) |
16 | game.Players.PlayerRemoving:connect( function (player) |
17 | RGBData:SetAsync(player, savetable) |
18 | end ) |
What you are doing, is when the player joins your game you simply get a sync from the data store. When the player leaves you do the opposite. Let me know if you have any additional questions.
You can use the functions HttpService:JSONEncode when saving the data, and HttpService:JSONDecode when retrieving.
01 | local dss = game:GetService( 'DataStoreServive' ):GetDataStore( 'Example' ) |
02 | local http = game:FindService( 'HttpService' ) |
03 |
04 | function save(key, value) |
05 | value = http:JSONEncode(value) |
06 | local success, message = pcall ( function () |
07 | dss:SetAsync(key, value) |
08 | end ) |
09 | return success, message |
10 | end |
11 |
12 | function retrieve(key) |
13 | return http:JSONDecode(dss:GetAsync(key)) or nil |
14 | end |
15 |
I found this youtube video helpful. At the beginning it is a bit slow and confusing but once you get through the video you should be able to do what you are trying to do. Here is the link
. Hope it helps!