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.
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.
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
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.