Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to fix following code "leaderstats with several loops, stats are deaths and time alive"?

Asked by 3 years ago

Hello, I am trying to make leaderboard stats, like number of deaths and seconds alive, that means when you die next time, it resets to 0. I am very new to scripting, and spent hours trying to fix that code, unsuccessfuly. Please can you fix it for me? Thank you very much.

game.Players.PlayerAdded:Connect(function(plr)

    local stats = Instance.new("Folder")
        stats.Name = "leaderstats"
    stats.Parent = plr

    local deaths = Instance.new("IntValue")
        deaths.Name = "Deaths"
        deaths.Parent = stats

    local timeafterdeath = Instance.new("IntValue")
    timeafterdeath.Name = "Time Alive"
    timeafterdeath.Parent = stats


    plr.CharacterAdded:Connect(function(char)
        local humanoid
        repeat
            humanoid = char:FindFirstChild("Humanoid")
        until humanoid
        repeat
            local plrname = plr.Name
            local characterpath = game.Workspace
            local characterhealth = (characterpath).(plrname).Health
            local dead = characterhealth == 0
            timeafterdeath.Value = timeafterdeath.Value + 1 
            wait(1)
        until dead
        humanoid.Died:Connect(function(died)
            deaths.Value = deaths.Value + 1
            timeafterdeath.Value = 0
        end)
    end)
end)



Answer this question