Disabling team kill in Roblox's official weapon kit

I’ve been modifying Roblox’s official weapon kit (Weapons Kit | Documentation - Roblox Creator Hub) for some time now, and I just noticed this kit doesn’t have a clear function that disables team killing.

I noticed there are from aspects regarding the player’s team mentioned in the main code, Line 754 has the following code:

self.weaponsSystem.playersOnDifferentTeams(self.weaponsSystem.getPlayerFromHumanoid(hitInfo.h), self.player))
then
self:applyDamage(hitInfo)

But this doesn’t seem to do anything, I’m not sure what else to do and I’m wondering if anyone else encountered this problem before and somehow created a fix for it.

Any help from anyone who has worked with these guns would be appreciated.

22 Likes

Hi sorry. I read this topic about 1 year ago and I finally found a solution.

For the solution you need to edit the WeaponsSystem module for ALL the weapons. (So that the wrong module script without anti teamkill would not be cloned into replicated storage.

RobloxOfficialWeaponsKitPicture
The image above shows where the WeaponsSystem module is in each weapon.

Step 1: Open up the module script and go to line 427 which is the function _defaultDamageCallback

Step 2: Replace all the code in the function with this;

if target:IsA("Humanoid") then
		local Player1 = game.Players:GetPlayerFromCharacter(dealer.Character)
		local Player2 = game.Players:GetPlayerFromCharacter(target.Parent)
		
		if Player1 then --  if the shooters player exists then
			if Player2 then -- If the thing you wanna damage is a Player and not an npc then

				local IsSameTeam = WeaponsSystem.playersOnSameTeam(Player1, Player2)

				if IsSameTeam == false then -- if players are not on same team
					target:TakeDamage(amount)
				end
			else -- target is an npc and not player (do what you want with this)
				target:TakeDamage(amount)
			end
			
		end
		
	end

Step 3: Go to line 494 just before “return WeaponsSystem” and paste this code to create the IsTeam function;

function WeaponsSystem.playersOnSameTeam(player1, player2)
	if player1.TeamColor == player2.TeamColor then
		return true
	else
		return false
	end	
end
6 Likes

Sorry for bumping into such an old topic. I hope this can help many developers.

1 Like

ahh team colour very useful… it only took 8 hours to be - well done :smile_cat:

1 Like

You need to make the teams first I forgot. You can use team name or team colour.

this didn’t work for me. i did what you said to do

1 Like

Before calling the take damage event, check if the attacker is on the same team as the person being attacked. This is done by using the Teams service. You can check their team color, or team name.

1 Like

it works now. i just forgot to what she said to do for the WeaponsSystem module in serverscriptservice. thank yall tho lol

1 Like