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

Problem with my leaderboard?

Asked by
Relatch 550 Moderation Voter
9 years ago

This script is supposed to give the player to killed another player 3 money, and 1 kill. But when I kill someone else, it doesn't work. It also don't get any errors. Help?

game.Players.PlayerAdded:connect(function(player)
    local leaderstats = Instance.new("Model")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = player

    local money = Instance.new("IntValue")
    money.Name = "Money"
    money.Value = 0
    money.Parent = leaderstats

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

    local level = Instance.new("IntValue")
    level.Name = "Level"
    level.Value = 1
    level.Parent = leaderstats

    game.Players.PlayerAdded:connect(function(player)
        player.CharacterAdded:connect(function(character)
            character.Humanoid.Died:connect(function()
                local killer = character.Humanoid:findFirstChild("creator")
                if killer then
                    killer.leaderstats.Kills.Value = killer.Value.Kills.Value + 1
                    killer.leaderstats.Money.Value = killer.leaderstats.Money.Value + 3
                end
            end)
        end)
    end)
end)

0
Is the tag actually in the humanoid? You need to do this using a script. EzraNehemiah_TF2 3552 — 9y
0
This isn't even what i'm asking for. Relatch 550 — 9y
0
Is the creator in the humanoid? If not then you need to go into the link. EzraNehemiah_TF2 3552 — 9y

1 answer

Log in to vote
0
Answered by 9 years ago

You're using the PlayerAdded event twice. The second one isn't loading. Additionally, this should be in a severscript if it isn't already.

game.Players.PlayerAdded:connect(function(player)
    local leaderstats = Instance.new("Model")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = player

    local money = Instance.new("IntValue")
    money.Name = "Money"
    money.Value = 0
    money.Parent = leaderstats

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

    local level = Instance.new("IntValue")
    level.Name = "Level"
    level.Value = 1
    level.Parent = leaderstats

        player.CharacterAdded:connect(function(character)
            character.Humanoid.Died:connect(function()
                local killer = character.Humanoid:findFirstChild("creator")
                if killer then
                    killer.leaderstats.Kills.Value = killer.Value.Kills.Value + 1
                    killer.leaderstats.Money.Value = killer.leaderstats.Money.Value + 3
                end
            end)
        end)
    end)
0
What's the "creator" inside of the humanoid? aquathorn321 858 — 9y
0
You can have multiple of the same events inside of each other, It's just not really needed. EzraNehemiah_TF2 3552 — 9y
0
Still isn't working. Relatch 550 — 9y
0
It would help if I knew what the "creator" inside of humanoid was. That seems to be your problem. And using PlayerAdded twice means it will create a huge mess of irrelevant code for every player that enters. aquathorn321 858 — 9y
0
Your problem might be having CharacterAdded so close to the bottom of the code. It might not be running the first time the character is loaded. aquathorn321 858 — 9y
Ad

Answer this question