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

How do you make it so that every time someone gets 12 kills, they get 1 Rebirth?

Asked by 3 years ago

I am trying to make a game that includes sword fighting and every time someone in the game gets 12 kills, they get 1 Rebirth. The 12 kills aren't supposed to go down to zero. I have a code for this, but I do not know how to keep adding the number 12 to prevent it from just getting 1 rebirth and if you get 24 kills, there would be no 2 rebirths.

local Players = game.Players

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

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


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
                            local Kills = Killer.leaderstats.Kills
                            Kills.Value = Kills.Value + 1
                            if Kills.Value == 12 then -- This code only appears to be the required Kills as 12, not 24, 36, 48. It doesn't add on to add 1 for Rebirth Value.
                                local Rebirth = Killer.leaderstats.Rebirth
                                Rebirth.Value = Rebirth.Value + 1
                            end
                        end
                    end
                end
            end)
        end
    end)
end)

Can someone please help me?

1 answer

Log in to vote
0
Answered by 3 years ago

I also used to struggle on this but what I did is to make a "Next Kills" value.

local NextKills = Instance.new("IntValue",plr)
NextKills.Value = 12


Instead of if Kills.Value == 12 then Try:

if Kills.Value == NextKills.Value then
    local Rebirth = Killer.leaderstats.Rebirth
    Rebirth.Value = Rebirth.Value + 1
    NextKills.Value = NextKills.Value + 12
end

I did not test it but go give it a try.

0
Alright! I'll give this a try! I'll inform you when this is correct TestAccount_PinkLeaf 14 — 3y
0
THANK YOU! IT WORKS! TestAccount_PinkLeaf 14 — 3y
0
Np AProgrammR 398 — 2y
Ad

Answer this question