Heal all players in the same team as player

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? i wanted to make an ability to heal all players in the same team as me

  2. What is the issue? i can’t think of how i can code it. here’s my unfinished code:

script.Parent.ChangeChar.OnServerEvent:Connect(function(OnPlayer)
	local CastAbility = game.ReplicatedStorage.CastAbility
	local name = script.Parent.Parent.Name
	local player = game:GetService("Players").name
	local team = player.Team 
	local red = game:GetService("Teams")["Red"]
	local blue = game:GetService("Teams")["Blue"]

	if team == red then

	--heal for red members only

	elseif team == blue then

	--heal for  blue members only

	end
		

	script.Parent.AbilityActive.Value = false
	script.Parent.ReturnChar:FireClient(OnPlayer)

end)
  1. What solutions have you tried so far? i have tried looking to the internet, but i can’t find any solution

this code is gonna be placed in a tool

If you have the player, here’s what you can do.

You can get the player character in any preferred way you like. For this, we’ll do:

local Character = player.Character or player.CharacterAdded:Wait()

Next, we will get their Humanoid through their character. We will then add their health using “+=”.

local Humanoid = Character.Humanoid;

Humanoid.Health += 50 -- interchangeable to whatever value you like.

I hope this helps!

Get each player from the team that needs to be healed, grab the humanoid and increase/set the health.

local healAmount = 20 -- Amount to heal
local MaxDistance = 20 -- Heals player if they are within a certain distance
HealPlayersRemotEvent.OnServerEvent:Connect(function(ourPlayer) -- Assuming a remoteevents fires to heal players.
	local ourCharacter = ourPlayer.Character -- our character
	for _,player in game.Players:GetPlayers()
		if player.Team == ourPlayer.Team then -- we see if player is on our team
			local character = player.Character -- the friendly players charcter
			local humanoid = character.Humanoid
			if (character.PrimaryPart.Position-ourCharacter.PrimaryPart.Position).Magnitude < MaxDistance then -- we do distance checks
				humanoid.Health += healAmount -- health added
			end
		end
	end
end)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.