Anti team player damge

if plr.Team ~= target.Team then 
      targetHumanoid:TakeDamage(damage)
end

Someone gave me this example before but I don’t know how to use it. I just know that I need to use the player service
and that I need something that works for most weapons
This is a very simple example and I think a more professional version is really needed.

I have different weapons in my game, and each one has different damage. Is there a way to do this in the server script service without having to customize each weapon?

goto your central Damage System or however you are inflicting damage to other players, and add that line that someone gave you.

DAMAGE SYSTEM:

where is says :TakeDamage(damage) → replace it with if Player.Team ~= Enemy.Team then Enemy.Humanoid:TakeDamage(DAMAGE NUMBER) end

if you still don’t know how to do it, post your damage system → thing how you inflict damage here and you will get help :+1:

You can write a function that determines whether or not the tool’s user is able to damage a given character

--[[ Variables ]]--
-- Services --
local Players = game:GetService("Players")

-- Tool --
local tool = script.Parent
local userCharacter = nil

--[[ Functions ]]--
local function canDamage(targetCharacter : Model) : boolean
	local userPlayer = Players:GetPlayerFromCharacter(userCharacter)
	local targetPlayer = Players:GetPlayerFromCharacter(targetCharacter)
	
	--// NPC case
	if userPlayer ~= nil or targetPlayer ~= nil then
		return true
	end
	
	local isTeammate = userPlayer.Team == targetPlayer.Team
	if isTeammate then
		return false
	end
	
	return true
end

local function damageTarget(targetCharacter : Model) : ()
	if not canDamage(targetCharacter) then
		return
	end
	
	targetCharacter.Humanoid:TakeDamage(...)
end

local function onEquipped() : ()
	userCharacter = tool.Parent
end
tool.Equipped:Connect(onEquipped)

I would recommend putting a function like that in a module if it’s going to be used by many scripts in your game so it’s easier to make changes without having to go through and edit each script that uses it, but it’s not necessary