So what im trying to achieve is saving Color3Values and then loading them again. My current code looks like this
Loading:
game.Players.PlayerAdded:Connect(function(player)
local vehiclesFolder = Instance.new("Model",workspace)
vehiclesFolder.Name = player.Name.." Vehicles"
local folder = Instance.new("Folder",player)
folder.Name="leaderstats"
local codes = Instance.new("Folder",player)
codes.Name="Codes"
local other = Instance.new("Folder",player)
other.Name="Other"
local awardedCars = Instance.new("Folder",workspace)
awardedCars.Name = "awardedCars_"..player.Name
local money = Instance.new("IntValue",folder)
money.Name="Money"
local vf=Instance.new("Folder",player)
vf.Name="OwnedVehicles"
for i,companies in pairs(game.ReplicatedStorage.Vehicles:GetChildren()) do
for i,car in pairs(companies:GetChildren()) do
local c=Instance.new("IntValue",vf)
c.Name=car.Name
local carColor = Instance.new("Color3Value")
carColor.Parent = player.OwnedVehicles[car.Name]
carColor.Name = "BodyColor"
end
end
for i,coder in pairs(code) do
local c=Instance.new("IntValue",codes)
c.Name=code[i]:lower()
end
for i,o in pairs(others) do
local c=Instance.new(others[i].Type,other)
c.Name=others[i].Name
c.Value=others[i].Value
end
local key = "fullboostkey_" .. tostring(player.UserId)
print("Player "..player.Name.." joined with the key "..key)
local data
local carData
local codeData
local customizationData
local suc,fai = pcall(function()
data = driftDataStore:GetAsync(key)
carData = vehicleData:GetAsync(key)
codeData = codeDatastore:GetAsync(key)
customizationData = customization:GetAsync(key)
end)
if suc then
if data.Money then
player.leaderstats.Money.Value = data.Money
else
print("User "..player.Name.." has no stats!")
player.leaderstats.Money.Value = 0
end
for i,companies in pairs(game.ReplicatedStorage.Vehicles:GetChildren()) do
for i,car in pairs(companies:GetChildren()) do
player.OwnedVehicles[car.Name].Value=carData[car.Name]
if customizationData and customizationData[car.Name] then
player.OwnedVehicles[car.Name].BodyColor.Value=customizationData[car.Name]
else
player.OwnedVehicles[car.Name].BodyColor.Value=Color3.fromRGB(248, 248, 248)
end
end
end
for i,c in pairs(codes:GetChildren()) do
c.Value=codeData[code[i]:lower()]
end
print("Sucessfully loaded data for "..player.Name)
else
print("Failed to load data for "..player.Name)
warn(fai)
end
if data then
else
end
end)
Saving:
game.Players.PlayerRemoving:Connect(function(player)
local key = "fullboostkey_" .. tostring(player.UserId)
print("Player leaving with key: "..key)
local m={
Money = player.leaderstats.Money.Value;
}
local n={}
local x={}
local c={}
for i,car in pairs(player.OwnedVehicles:GetChildren()) do
n[car.Name]=player.OwnedVehicles[car.Name].Value
c[car.Name]=player.OwnedVehicles[car.Name].BodyColor.Value
end
for i,c in pairs(player.Codes:GetChildren()) do
x[code[i]:lower()]=player.Codes[code[i]:lower()].Value
end
local success,failure = pcall(function()
driftDataStore:SetAsync(key,m)
vehicleData:SetAsync(key,n)
codeDatastore:SetAsync(key,x)
customization:SetAsync(key,c)
end)
if success then
print("Successfully saved data!")
else
print("There was an error while saving data!")
warn(failure)
end
end)
I’ve tried alot but it just reverts to default white which means data must have not been saved?