i tried everything , but cant fix the code


local DataStore = game:GetService("DataStoreService")
local SecondsSave = DataStore:GetDataStore("SecondsSaveSystem")
local KronosSave = DataStore:GetDataStore("KronosSaveSystem")

local Players = game:GetService("Players")

local function GetSaveSeconds(Player)
    if not (Player and Player:IsA("Player")) then return end
    local Seconds;
    local Success = pcall(function()
        Seconds = SecondsSave:GetAsync(Player.UserId)
    end)
    if (Success and Seconds) then 
        return Seconds.Value
    end
    return nil
end

local function GetSaveKronos(Player)
    if not (Player and Player:IsA("Player")) then return end
    local Kronos;
    local Success = pcall(function()
        Kronos = KronosSave:GetAsync(Player.UserId)
    end)
    if (Success and Kronos) then 
        return Kronos.Value
    end
    return nil
end

local function SaveData1(Player)
    if not (Player and Player:IsA("Player")) then return end
    local Leaderstats = Player:FindFirstChild("leaderstats",1)
    local Seconds = Leaderstats:FindFirstChild("Seconds",1)
    local _,Unsuccessful = pcall(function()
        SecondsSave:SetAsync(Player.UserId, Seconds.Value)
    end)
    if (Unsuccessful) then warn(Unsuccessful) end
end

local function SaveData2(Player)
    if not (Player and Player:IsA("Player")) then return end
    local Leaderstats = Player:FindFirstChild("leaderstats",1)
    local Kronos = Leaderstats:FindFirstChild("Kronos",1)
    local _,Unsuccessful = pcall(function()
        KronosSave:SetAsync(Player.UserId, Kronos.Value)
    end)
    if (Unsuccessful) then warn(Unsuccessful) end
end



Players.PlayerAdded:Connect(function(Player)
    local Leaderstats = Instance.new("Folder"); Leaderstats.Parent = Player
    Leaderstats .Name = "leaderstats"

    local Seconds = Instance.new("IntValue"); Seconds.Parent = Leaderstats
    Seconds.Name = "Seconds"
    Seconds.Value = GetSaveSeconds()(Player) or 0
    Seconds:GetPropertyChangedSignal("Value"):Connect(function()
        SaveData1(Player)
    local Leaderstats = Instance.new("Folder"); Leaderstats.Parent = Player
    Leaderstats .Name = "leaderstats"
    local Kronos = Instance.new("Folder"); Leaderstats.Parent = Players
    Kronos.Name = "Kronos"
    Kronos.Vaule = GetSaveKronos()(Players) or 0
    Kronos:GetPropertyChangedSignal("Vaule"):Connect(function()
	    SaveData2(Players)
    end)
end)


Players.PlayerRemoving:Connect(SaveData1)
Players.PlayerRemoving:Connect(SaveData2)

2 comments

0

Please fix the formatting (lack of indenting and code block) it's a nuisance to read like this

0

What is the error?