Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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.

3 comments

0

Alright! I'll give this a try! I'll inform you when this is correct

0

THANK YOU! IT WORKS!

0

Np

This discussion is preserved as it was. New answers, comments, and votes are closed.