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

Leaderboard help . Add points to gui?

Asked by
TrollD3 105
9 years ago

I have a script that adds your deaths and kills in a game. How would I make it so that when a players receives points, it adds 1 point to their team leader board (teams = atlas/sentinel). I have the team leaderboard in a gui. That gui has a frame and with textbuttons under them.

print("Leaderboard script loaded")


function onPlayerEntered(newPlayer)


    local stats = Instance.new("IntValue")
    stats.Name = "leaderstats"

    local kills = Instance.new("IntValue")
    kills.Name = "Kills"
    kills.Value = 0

    local deaths = Instance.new("IntValue")
    deaths.Name = "Deaths"
    deaths.Value = 0

    kills.Parent = stats
    deaths.Parent = stats

    local humanoid = newPlayer.Character.Humanoid
    humanoid.Died:connect(function() onHumanoidDied(humanoid, newPlayer) end )

    -- start to listen for new humanoid
    newPlayer.Changed:connect(function(property) onPlayerRespawn(property, newPlayer) end )


    stats.Parent = newPlayer

end

function onHumanoidDied(humanoid, player)
    local stats = player:findFirstChild("leaderstats")
    if stats ~= nil then
        local deaths = stats:findFirstChild("Deaths")
        deaths.Value = deaths.Value + 1
        handleKillCount(humanoid, player)
    end
end

function onPlayerRespawn(property, player)
    -- need to connect to new humanoid

    if property == "Character" then
        local humanoid = player.Character.Humanoid
            local p = player
            local h = humanoid
            humanoid.Died:connect(function() onHumanoidDied(h, p) end )
    end
end


function handleKillCount(humanoid, player)
    -- todo, killing self results in negative points.

    -- check for kill tag on humanoid - may be more than one - todo: deal with this
    local tag = humanoid:findFirstChild("creator")

    -- find player with name on tag
    if tag ~= nil then

        local killer = tag.Value
        if killer.Parent ~= nil then

            -- test if killer still in game, 
            local stats = killer:findFirstChild("leaderstats")
            if stats ~= nil then
                local kills = stats:findFirstChild("Kills")
                if killer ~= player then
                    kills.Value = kills.Value + 1

                else
                    kills.Value = kills.Value - 1

                end
            end
        end
    end 

end

game.Players.ChildAdded:connect(onPlayerEntered)

Answer this question