local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local Saver = DataStoreService:GetDataStore("FootballPlayers1")
Players.PlayerAdded:Connect(function(player)
print("Player added:", player.Name)
local Data = nil
local success, errormessage = pcall(function()
Data = Saver:GetAsync(tostring(player.UserId))
end)
if success then
print("Data loaded successfully for player:", player.Name)
if Data then
print("Loaded data:", Data)
for dataKey, colorData in pairs(Data) do
print("Processing dataKey:", dataKey, "with colorData:", colorData)
-- Expected key format: "Position_SkinColor" (e.g., "HB_SkinColor")
local parts = string.split(dataKey, "_")
if #parts == 2 then
local positionName = parts[1]
local propertyName = parts[2]
print("Extracted positionName:", positionName, "and propertyName:", propertyName)
local positionFolder = player:WaitForChild("TeamPlayers"):FindFirstChild(positionName)
if positionFolder then
print("Found positionFolder:", positionFolder.Name)
if propertyName == "SkinColor" then
local colorValue = Instance.new("Color3Value")
colorValue.Name = propertyName
colorValue.Value = Color3.fromRGB(colorData.R, colorData.G, colorData.B)
print("Setting SkinColor for", positionName, "to", colorValue.Value)
colorValue.Parent = positionFolder
end
else
print("Position folder not found:", positionName)
end
end
end
else
print("No data found for player:", player.Name)
end
else
warn("Error loading data for player:", player.Name, errormessage)
end
end)
local function Save(player)
print("Saving data for player:", player.Name)
local SavedData = {}
local teamPlayers = player:FindFirstChild("TeamPlayers")
if teamPlayers then
for _, positionFolder in pairs(teamPlayers:GetChildren()) do
if positionFolder:IsA("Folder") then
local skinColorValue = positionFolder:FindFirstChild("SkinColor")
if skinColorValue and skinColorValue:IsA("Color3Value") then
local key = positionFolder.Name .. "_SkinColor"
local color = skinColorValue.Value
SavedData[key] = {R = math.floor(color.R * 255), G = math.floor(color.G * 255), B = math.floor(color.B * 255)}
print("Saving color for", positionFolder.Name, ":", SavedData[key])
end
end
end
end
print("Data to be saved:", SavedData)
local success, errormessage = pcall(function()
Saver:SetAsync(tostring(player.UserId), SavedData)
end)
if not success then
warn("Error saving data for player:", player.Name, errormessage)
else
print("Data saved successfully for player:", player.Name)
end
end
Players.PlayerRemoving:Connect(Save)
game:BindToClose(function()
print("Game is closing, saving data for all players.")
for _, v in pairs(Players:GetPlayers()) do
Save(v)
end
end)
I asked chatgpt to add debug print statements, run this and see if it’s still working, i dont think it changed the logic but it might have, this will help me figure out where the problem lies though
Also send a video / the output when you run this, so im able to actually see what it’s doing wrong