local o=game:GetService("\080\108\097\121\101\114\115")local T=game:GetService("\082\117\110\083\101\114\118\105\099\101")local m={}o.PlayerAdded:Connect(function(o)m[o]=tick()end)o.PlayerRemoving:Connect(function(o)m[o]=nil end)for o,T in pairs(o:GetPlayers())do m[T]=tick()end return function(T,m,M,N)local y={}local function k(o,m)return y[m]~=nil and tick()-y[m]>T end return{id="\083\101\115\115\105\111\110\076\101\110\103\116\104\095"..T,name=m;desc=M,badgeId=N,startListening=function(T,M)print("\076\105\115\116\101\110\105\110\103 \102\111\114",m)spawn(function()while true do for o,m in pairs(o:GetPlayers())do if not y[m]then y[m]=tick()end if k(T,m)then M(m)end end wait(.3)end end)end;queryComplete=k}end
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local joinTimes = {}

Players.PlayerAdded:Connect(function(player)
    joinTimes[player] = tick()
end)

Players.PlayerRemoving:Connect(function(player)
    joinTimes[player] = nil
end)

for _,player in pairs(Players:GetPlayers()) do
    joinTimes[player] = tick()
end

return function(timeRequirement,name,desc,badgeId)

    local joinTimes = {}
    -- function that returns true if a player has completed this objective
    local function queryComplete(server,player)
        return (joinTimes[player] ~= nil) and ((tick() - joinTimes[player]) > timeRequirement)
    end

    return {
        id = "SessionLength_"..timeRequirement,
        name = name,
        desc = desc,
        badgeId = badgeId,
        startListening = (function(server, awardBadge)
            print("Listening for",name)
            spawn(function()
                while true do
                    for _,player in pairs(Players:GetPlayers()) do
                        if not joinTimes[player] then
                            joinTimes[player] = tick()
                        end
                        if queryComplete(server,player) then
                            awardBadge(player)
                        end
                    end
                    wait(0.3)
                end
            end)
        end),
        queryComplete = queryComplete,
    }
end