Help with lifesteal

I have this kill leaderboard:

local Players = game.Players

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

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


Players.PlayerAdded:connect(function(Player)
	wait(1)
	local Stats = Template:Clone()
	Stats.Parent = Player
	local Deaths = Stats.Deaths
	Player.CharacterAdded:connect(function(Character)
		Deaths.Value = Deaths.Value + 1
		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
						end
						return 
					end
				end
			end)
		end
	end)
end)

I was thinking when your kill counter goes up you could make your max health go up. How would I do this?

A simple way to compute this would be like so.

-- in CharacterAdded
Humanoid.Health = Kills.Value * 10 + 100

What have you tried? What parts are you struggling with?

would i put this code in where i get +1 kill? I need your max health to increase by 10 each time you get a kill.

Right under this line simply put

Humanoid.MaxHealth += 10

This adds 10 to the humanoids health.

I have this save script to save the kills and deaths.

--[[Savin'
		Dem
			Stats	
--]]
game.Players.PlayerRemoving:connect(function(player)
	local datastore = game:GetService("DataStoreService"):GetDataStore(player.Name.."Stats")

	local statstorage = player:FindFirstChild("leaderstats"):GetChildren()
	for i =  1, #statstorage do
		datastore:SetAsync(statstorage[i].Name, statstorage[i].Value)
		print("saved data number "..i)

	end
	print("Stats successfully saved")	
end)


--[[
	Loadin'
		Dem
			Stats
--]]
game.Players.PlayerAdded:connect(function(player)
	local datastore = game:GetService("DataStoreService"):GetDataStore(player.Name.."Stats")

	player:WaitForChild("leaderstats")
	wait(1)
	local stats = player:FindFirstChild("leaderstats"):GetChildren()
	for i = 1, #stats do			
		stats[i].Value = datastore:GetAsync(stats[i].Name)
		print("stat numba "..i.." has been found")
	end
end)


Would this save the health? If not how would i save it?

I think the health only goes to 110. Why is this?

When you’re loading the kills and registering another kills your need to add this line:

humanoid.MaxHealth == kills.Value*10+100

This will add 10 for each kill and it’ll also load it and add it every time you get a kill

Ok so replace
Humanoid.MaxHealth += 10
with
humanoid.MaxHealth == kills.Value*10+100
Or should I put that line one after another?

No, that’s how you have to do it, you only need to keep the last one

ok ill only keep humanoid.MaxHealth == kills.Value*10+100

local Players = game.Players

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

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


Players.PlayerAdded:connect(function(Player)
	wait(1)
	local Stats = Template:Clone()
	Stats.Parent = Player
	local Deaths = Stats.Deaths
	Player.CharacterAdded:connect(function(Character)
		Deaths.Value = Deaths.Value + 1
		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
							local Health = Killer.leaderstats.Health
							Kills.Value = Kills.Value + 1
							Health.Value = Health.Value + 10
							humanoid.MaxHealth == Kills.Value*10+100
							Humanoid.Health += 10
						end
						return 
					end
				end
			end)
		end
	end)
end)

humanoid.MaxHealth == Kills.Value*10+100 has an error

What is the error?

Might need to do:

humanoid.MaxHealth == (Kills.Value * 10 + 100)

The reason it errors is because you should only use one equals symbol and not two, else you’re comparing them and checking if they’re equal. If you use one, then you assign the value to MaxHealth. So change it to:

humanoid.MaxHealth = Kills.Value * 10 + 100

2 Likes

This is part of the code, where when you get a kill you get +10 health and when you die you get minus 10 health.

local Kills = Killer.leaderstats.Kills
							local Health = Killer.leaderstats.Health
							Kills.Value = Kills.Value + 1
							Health.Value = Health.Value + 10
							Humanoid.MaxHealth = Kills.Value*10+100 - Deaths.Value*10

There are no errors, would this work?

Yes, bust your need to change MaxHealth before Health as it’ll not work if you don’t

local Kills = Killer.leaderstats.Kills
							local Health = Killer.leaderstats.Health
							Kills.Value = Kills.Value + 1
				
Humanoid.MaxHealth = Kills.Value*10+100 - Deaths.Value*10

			Health.Value = Health.Value + 10

What?
I don’t understand, can you show us the full script again?

local Players = game.Players

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

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


Players.PlayerAdded:connect(function(Player)
	wait(1)
	local Stats = Template:Clone()
	Stats.Parent = Player
	local Deaths = Stats.Deaths
	Player.CharacterAdded:connect(function(Character)
		Deaths.Value = Deaths.Value + 1
		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
							local Health = Killer.leaderstats.Health
							Kills.Value = Kills.Value + 1
							Health.Value = 100

							Humanoid.MaxHealth = Kills.Value*10+100 - Deaths.Value*10

							Health.Value = Health.Value + 10
							
						end
						return 
					end
				end
			end)
		end
	end)
end)

I have a leaderboard saying your health but you spawn with 0 health on the leaderboard. Also, how would I make you get banned for 1 hour when you lose all your health with a message.

That’s because you’re not setting the value at first, so it’s stays 0 because it’s the default

I’m not sure why it stays at 10 health but to ban someone put them in a Datastore and make a function to check time and when they come in check if they’re Banned and then if they are kick them (not sure how to script it tho)

How would I make the value start at 100? where would I insert the line?

You would add it just after you create it