I know you can’t save colors in a datastore, so I tried making a way to get around it. What I tried isn’t working. I tried converting the color value to a string and it converted, but I can’t get the value.
Script:
local DataStoreService = game:GetService("DataStoreService")
local PlayerData = DataStoreService:GetDataStore("SaveMoney")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Parent = player
leaderstats.Name = "leaderstats"
local Cash = Instance.new("IntValue")
Cash.Parent = leaderstats
Cash.Name = "Cash"
local RPName = Instance.new("StringValue")
RPName.Name = "RPName"
RPName.Parent = player
local RPBio = Instance.new("StringValue")
RPBio.Name = "RPBio"
RPBio.Parent = player
local NameCol = Instance.new("Color3Value")
NameCol.Name = "NameCol"
NameCol.Parent = player
local LoadData
local success,failure = pcall(function()
LoadData = PlayerData:GetAsync(player.UserId.."-Data")
end)
if success then
if LoadData ~= nil then
Cash.Value = LoadData.Cash
RPName.Value = LoadData.Name or ""
RPBio.Value = LoadData.Bio or ""
NameCol.Value = Color3.new(LoadData.NC) or Color3.fromRGB(255, 255, 255)
else
Cash.Value = 25000
RPName.Value = player.Name
RPBio.Value = ""
NameCol.Value = Color3.fromRGB(255, 255, 255)
end
print("Loaded "..player.Name)
else
print("Failed to load "..player.Name)
warn(failure)
end
end)
local function SaveData(player)
local DataToSave = {
Cash = player.leaderstats.Cash.Value;
Name = player.RPName.Value;
Bio = player.RPBio.Value;
NC = tostring(player.NameCol.Value)
}
local success, failure = pcall(function()
PlayerData:SetAsync(player.UserId.."-Data", DataToSave)
end)
if not success then
print("Failed to save "..player.Name)
warn(failure)
end
end
local gameClosing = false
game.Players.PlayerRemoving:Connect(function(player)
wait()
if not gameClosing then
SaveData(player)
end
end)
game:BindToClose(function()
gameClosing = true
for _,player in pairs(game.Players:GetChildren()) do
SaveData(player)
end
end)
local DataStoreService = game:GetService("DataStoreService")
local PlayerData = DataStoreService:GetDataStore("SaveMoney")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Parent = player
leaderstats.Name = "leaderstats"
local Cash = Instance.new("IntValue")
Cash.Parent = leaderstats
Cash.Name = "Cash"
local RPName = Instance.new("StringValue")
RPName.Name = "RPName"
RPName.Parent = player
local RPBio = Instance.new("StringValue")
RPBio.Name = "RPBio"
RPBio.Parent = player
local NameCol = Instance.new("Color3Value")
NameCol.Name = "NameCol"
NameCol.Parent = player
local LoadData
local success,failure = pcall(function()
LoadData = PlayerData:GetAsync(player.UserId.."-Data")
end)
if success then
if LoadData ~= nil then
Cash.Value = LoadData.Cash
RPName.Value = LoadData.Name or ""
RPBio.Value = LoadData.Bio or ""
NameCol.Value = Color3.fromRGB(LoadData.NC.R,LoadData.NC.G,LoadData.NC.B) or Color3.fromRGB(255, 255, 255)
else
Cash.Value = 25000
RPName.Value = player.Name
RPBio.Value = ""
NameCol.Value = Color3.fromRGB(255, 255, 255)
end
print("Loaded "..player.Name)
else
print("Failed to load "..player.Name)
warn(failure)
end
end)
local function SaveData(player)
local NC = {}
NC.R = player.NameCol.Value.R
NC.G = player.NameCol.Value.G
NC.B = player.NameCol.Value.B
print(NC)
local DataToSave = {
Cash = player.leaderstats.Cash.Value;
Name = player.RPName.Value;
Bio = player.RPBio.Value;
NC
}
local success, failure = pcall(function()
PlayerData:SetAsync(player.UserId.."-Data", DataToSave)
end)
if not success then
print("Failed to save "..player.Name)
warn(failure)
end
end
local gameClosing = false
game.Players.PlayerRemoving:Connect(function(player)
wait()
if not gameClosing then
SaveData(player)
end
end)
game:BindToClose(function()
gameClosing = true
for _,player in pairs(game.Players:GetChildren()) do
SaveData(player)
end
end)
NC.R = player.NameCol.Value.R
I think this gives the R value from 0-1 instead of 0-255, so don’t use fromRGB when loading it
I’m not sure about the error though