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

Does't give points at first kill, but it does on second and so on?

Asked by
CjayPlyz 643 Moderation Voter
6 years ago

when you kill someone u get points.. but it only give points after the first kill.

here is the script

local Players = game.Players

local Template = Instance.new 'BoolValue'
Template.Name = 'leaderstats'

Instance.new('IntValue', Template).Name = "Kills"
Instance.new('IntValue', Template).Name = "Coins"

local db = 0

Players.PlayerAdded:connect(function(Player)
    wait(1)
    local Stats = Template:Clone()
    Stats.Parent = Player
    Player.CharacterAdded:connect(function(Character)
        local Humanoid = Character:FindFirstChild "Humanoid"
        if Humanoid then
            Humanoid.Died:connect(function()
                for i, Child in pairs(Humanoid:GetChildren()) do
                    if Child:IsA('ObjectValue') and Child.Value and Child.Value:IsA('Player') then
                        local Killer = Child.Value
                        if Killer:FindFirstChild 'leaderstats' and Killer.leaderstats:FindFirstChild "Kills" then
                            if db == 0 then
                            db = db + 1
                            local Kills = Killer.leaderstats.Kills
                            local Coins = Killer.leaderstats.Coins
                            Kills.Value = Kills.Value + 1
                            Coins.Value = Coins.Value + 2
                            wait(1)
                            db = db - 1
                            else return end
                        end
                        return
                    end
                end
            end)
        end
    end)
end)

1 answer

Log in to vote
0
Answered by
Ryrasil 30
6 years ago

When someone joins their character gets added pretty quickly so the CharacterAdded event probably only gets called after the person resets, you should debug the CharacterAdded event to check if this is correct.

0
oh ok wait CjayPlyz 643 — 6y
0
just checked, it was not the problem CjayPlyz 643 — 6y
0
wait it is the problem ok just fixed it thanks CjayPlyz 643 — 6y
Ad

Answer this question