How to make a team-member not get damaged

Hello, so what im trying to achieve is basically, i got a script in which, im trying to make it so whenever i shoot someone, it checks their team, and if the team is the same as you’r team, then they wont get damaged, but if they’re from a different team, then damage them.

local ReplicatedStorage = game:GetService('ReplicatedStorage')
local remoteEvent = ReplicatedStorage:WaitForChild('Pistol1')
local hit = ReplicatedStorage.Hit
local DamageToDoIfTheHitIsAPlayer = 0


remoteEvent.OnServerEvent:Connect(function(player, gunPos, gunOr, mosPos)
	game:GetService("ReplicatedStorage").Gun_Shot2:Play()
	local bullet = Instance.new("Part")
	bullet.Transparency = 0
	bullet.Name = 'Bullet'
	bullet.Parent = game.Workspace
	bullet.Size = Vector3.new(1.25, 1.25, 1.25)
	bullet.BrickColor = BrickColor.new('White')
	bullet.Shape = Enum.PartType.Block
	bullet.CanCollide = false

	local speed = 500
	bullet.CFrame = CFrame.new(gunPos, mosPos)
	bullet.Velocity = bullet.CFrame.lookVector * speed

	bullet.Touched:Connect(function(otherPart) 
		local humanoid = otherPart.Parent:FindFirstChild('Humanoid')
		if humanoid and humanoid.Parent.Name ~= player.Name then
			local plr = game.Players:GetPlayerFromCharacter(otherPart.Parent)
			if humanoid.Health > 0 then
				humanoid:TakeDamage(math.random(5, 7))
				local particleEmitter = ReplicatedStorage.Blood:Clone()
				particleEmitter.Parent = otherPart
				hit:Play()
				particleEmitter:Emit()
				wait(1)
				particleEmitter:Destroy()
				if humanoid.Health == 0 then
					bullet:Destroy()
				end
			end
		end
	end)
end)

Just add a check the same way you added:

if humanoid and humanoid.Parent.Name ~= player.Name then

Add a check for the team:

if plr.Team ~= player.Team then
	if humanoid.Health > 0 then
		humanoid:TakeDamage(math.random(5, 7))
		local particleEmitter = ReplicatedStorage.Blood:Clone()
		particleEmitter.Parent = otherPart
		hit:Play()
		particleEmitter:Emit()
		wait(1)
		particleEmitter:Destroy()
		if humanoid.Health == 0 then
			bullet:Destroy()
		end
	end
end
1 Like

Bingo!

(30 letterrrrrrrrr limit)