So I have a datastore that worked before just saving cash the script for that one is
StatsInfo = {
{Name = 'Cash', Start = 100, Max = 50000000000, Type = 'DoubleConstrainedValue'},
}
Data = game:GetService'DataStoreService':GetDataStore'PlayerData'
game.Players.ChildAdded:connect(function(p)
local stats = Instance.new('Folder', p)
stats.Name = 'leaderstats'
for _,v in pairs(StatsInfo) do
local value = Instance.new(v.Type, stats)
value.Name = v.Name
if v.Max then
value.MaxValue = v.Max
end
if v.Min then
value.MinValue = v.Min
end
if v.Start then
value.Value = v.Start
end
end
local data = Data:GetAsync('Save_'..p.userId)
if data then
for i,v in pairs(data) do
if stats:FindFirstChild(v.name) then
stats[v.name].Value = v.value
end
end
print(p.Name.."'s data has been loaded.")
end
end)
game.Players.PlayerRemoving:connect(function(p)
local ls = p:FindFirstChild'leaderstats'
if ls then
local DataToSave = {}
for i,v in pairs(ls:GetChildren()) do
table.insert(DataToSave, {name = v.Name, value = v.Value})
end
pcall(function()
Data:SetAsync('Save_'..p.userId, DataToSave)
print(p.Name.."'s data has been saved.")
end)
end
end)
game.OnClose = function()
wait(3)
end
Now I had it save the color that the player wanted to customize the shield so I had some help and we added this. After we added this it stopped saving cash. The color or cash never saved. Is there an issue with the ds?
StatsInfo = {
{Name = 'Cash', Start = 100, Max = 50000000000, Type = 'DoubleConstrainedValue'},
{Name = 'ShieldPrimaryColor', Start = Color3.fromRGB(255, 255, 255)--[[ Replace with color ]], Type = 'Color3Value'},
}
Data = game:GetService'DataStoreService':GetDataStore'PlayerData'
function getSaveableColor3(color)
print(color.r, color.g, color.b)
return {r = color.r, g = color.g, b = color.b}
end
function loadColorFromDataStore(t)
print(t.r, t.g, t.b)
return Color3.new(t.r, t.g, t.b)
end
game.Players.PlayerAdded:connect(function(Player)
local stats = Instance.new('Folder', Player)
stats.Name = 'leaderstats'
for _,v in pairs(StatsInfo) do
local value = Instance.new(v.Type, stats)
value.Name = v.Name
if v.Max then
value.MaxValue = v.Max
end
if v.Min then
value.MinValue = v.Min
end
if v.Start then
value.Value = v.Start
end
end
local data = Data:GetAsync('Save_'..Player.userId)
if data then
for i,v in pairs(data) do
if stats:FindFirstChild(v.name) then
if v.value.r and v.value.g and v.value.b then --
stats[v.name].Value = loadColorFromDataStore(v.value)
else
stats[v.name].Value = v.value
end
end
end
print(Player.Name.."'s data has been loaded.")
end
end)
game.Players.PlayerRemoving:connect(function(Player)
local ls = Player:FindFirstChild'data'
if ls then
local DataToSave = {}
for i,v in pairs(ls:GetChildren()) do
if typeof(v.Value) == "Color3" then
table.insert(DataToSave, {name = v.Name, value = getSaveableColor3(v.Value)})
else
table.insert(DataToSave, {name = v.Name, value = v.Value})
end
end
pcall(function()
Data:SetAsync('Save_'..Player.userId, DataToSave)
print(Player.Name.."'s data has been saved.")
end)
end
end)
game.OnClose = function()
wait(3)
end
