How would I make it so when you get a kill your max health gets increased by one?
How would I make it so when you die your max health gets de-creased by one?
For the first one, you could do something like this
Health:GetPropertyChangedSignal("Value"):Connect(function()
Health.Value += 1
end
How would I detect when you kill a player?
How do you want to kill players? With a sword, with a gun?
Not every tool are scripted the same, Fire the KilledBy
function when someone gets killed, And also the script is from ServerScriptService
local Players = game:GetService("Players")
local HealthBar = 10 --
local MaxHealths = {}
local function SetMaxHealth(Character)
local PlayerFrom = Players:GetPlayerFromCharacter(Character)
local Humanoid = Character:WaitForChild("Humanoid")
Humanoid.MaxHealth = MaxHealths[PlayerFrom]
end
local function KilledBy(Player, Killer)
MaxHealths[Player] -= HealthBar
if Killer then
MaxHealths[Killer] += MaxHealths
SetMaxHealth(Killer.Character)
end
SetMaxHealth(Player.Character or Player.CharacterAdded:Wait())
end
Players.PlayerAdded:Connect(function(Player)
MaxHealths[Player] = 100
SetMaxHealth(Player.Character or Player.CharacterAdded:Wait())
Player.CharacterAdded:Connect(SetMaxHealth)
end)
Players.PlayerRemoving:Connect(function(Player)
MaxHealths[Player] = nil
end)
Making a Lifesteal type game would be pretty simple concept, and not really that complicated to make, I’ll guide you through most of the steps.
When making this type of system, you have to take in the Amount of Damage the Humanoid has taken, when they die, and who killed them, do this with whatever weapon you are using whether its a gun, bomb, or just a Sword, for the Death system, we will look for a Tag called creator
(we will need to create this Tag ourselves everytime a Player hits another Player) and then check its Value, creator
should be an ObjectValue
so we can store the Player inside it, so when we check, it will make our search much easier, in order to create this “Tag”, we would do this:
function spawnTag(Attacker, TargetHumanoid)
-- Attacker Parameter is the Player who Attacked (The Player Instance)
-- TargetHumanoid is the Humanoid whose taking Damage
local creator = Instance.new("ObjectValue") -- creates an ObjectValue
creator.Name = "creator" -- the name of the ObjectValue
creator.Value = Attacker -- Assigns the Value as the Attacker
creator.Parent = TargetHumanoid -- places ObjectValue into our Target
end
But, this is just creating a Tag, there is no use for it at the moment, we need this Tag to work when the Player Dies, not just a random Accessory of the Player.
Before we Decide what to Grant the Player, we need to Decide whether the Player Killed Themselves (if you want that kind of system) or who Killed the Player, and you might be thinking: “Do we check for the ObjectValue??”, and you would be exactly right, we would check for it.
But before we do this, how would we check if they died? The Humanoid has a Event within it called Died
which is exactly what it sounds, it fires when the Players Die, when the Player is Dead, we check for this Value using FindFirstChild
to Avoid an Error for attempting index something nil
, and if it finds the Tag, we grant that Player the Health, and the Player loses Health.
However if you want the Change to be permanent, you use a Value, maybe a IntValue
to keep track of the Players Health, so when the Player dies, they dont get all their health back
Humanoid.Died:Connect(function()
local Tag = Humanoid:FindFirstChild("creator") -- Value or nil
local didPlayerDamage = (Tag ~= nil) -- This will return a boolean if there is a Tag
if didPlayerDamage then -- if this Boolean is true
local Killer = Tag.Value -- Gets the Player from Value
Killer.HealthValue += 1 -- Adds to their Health
end
Victim.HealthValue -= 1 -- Takes away from Player Health
end)
I want to kill them with a sword
Dirbie90 what would I have to do to your script to make it work? where would I put it? THANKS!
Not wise to change the same variable inside of its own change event. Will cause infinite loop.