I am currently trying to make a Color3 value save to a datastore using a table. I have a free to use GUI color picker and it used a HSV value so i converted it to RGB and now I’m trying to make the RGB color save to a leaderstat and then be able to access the datastore from another script to change the color of a part stored in ReplicatedStorage.
My issue is that I’m unsure how to access the datastore to use it once the player joins the game again. and also saving the Color3 value to a datastore using a table, when printing what the datastore saves its a bunch of numbers. And then when i use a playeradded event to try using the saved data it gives me errors
local script that sends the RGB values through a table
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local HttpsService = game:GetService("HttpService")
script.Parent.MouseButton1Click:Connect(function()
local ColorData = ({
r = script.Parent.Parent.Holder.Value.R,
g = script.Parent.Parent.Holder.Value.G,
b = script.Parent.Parent.Holder.Value.B })
ReplicatedStorage.RemoteEvents.SetBallColor:FireServer(ColorData)
end)
regular script where my datastore is held wirth the playeradded event - inside ServerScriptService
local DataStore = game:GetService("DataStoreService")
local BallColor = DataStore:GetDataStore("BallColorStore")
local players = game:GetService("Players")
--ColorData
local function saveData(Player, Data)
local DataToSave = Data
local success, err = pcall(function()
BallColor:SetAsync(Player.UserId, DataToSave, {R = DataToSave.ColorData.r, B = DataToSave.ColorData.b, G = DataToSave.ColorData.G})
end)
if success then
print("Data has been saved!")
print(DataToSave)
else
print("Data hasn't been saved!")
warn(err)
end
end
game.ReplicatedStorage.RemoteEvents.SetBallColor.OnServerEvent:Connect(function(Player, ColorData)
saveData(Player, ColorData)
print(ColorData)
end)
players.PlayerAdded:Connect(function(player)
local SavedData = game:GetService("DataStoreService"):GetDataStore("BallColorStore"):GetAsync(player.UserId)
if SavedData ~= nil then
ReplicatedStorage.Ball.Color = Color3.new(SavedData.R, SavedData.G, SavedData.B)
else
print("Data is nil")
end
end)
and this is what the output looks like whenever I try to test it.
now I’ve been trying for a little under 5 hours trying to get this to work. I’ve tried many different ways and different things and I’ve looked at probably about 100 different posts and youtube videos trying to figure it out. So I would be glad if someone would be willing to help me figure this out. Thank you for reading!