So i wanna make when a player kills another player, the player (killer) will get hp. But when i go to yt, i couldn’t find any.
Well you have to damage the player with the weapon so you can check if their health is less than or equal to the damage that the weapon does and if it is heal the attacker and apply the damage.
Okay so in the part of the script that does damage to the player you want it to check if the damage you do is greater than the current hp of the enemy
For example:
local playerHumanoid = game.Players.LocalPlayer.Character.Humanoid -- Your players humanoid
local enemyHumanoid = game.Players["EnemyName"].Character.Humanoid -- the enemys humanoid. Obviously this will be switched out in your script but it's an example here
local Damage = 50 -- the amount of damage being dealt
local healAmount = 25 -- the amount you heal if you kill a player
-- add in a check like this before the damage is inflicted on the enemy
if Damage >= enemyHumanoid.Health then
enemyHumanoid:TakeDamage(Damage) -- change this out for your script that damages/kill the enemy
playerHumanoid.Health = playerHumanoid.Health + healAmount -- adds the heal amount which is 25 to your current hp!
else
enemyHumanoid:TakeDamage(Damage) -- change this out for your script that damages/kill the enemy
end
hmm how do i make this line like for all players that are in the server ?
Well, the way It should be done is by editing whichever damage script you already have.
Let’s say, for example, You’re using a sword. It may use a Touched event. You would get the player from the attack hitting the player.
There are many examples you can use for this by simply searching in the dev forum, looking at youtube videos for basically any attack skill even weapons such as swords that will be able to explain it very detailed or using a real example.
If you were to make that line affect every player in the game, attacking 1 player would cause every player in the game to take damage.