I have only briefly played with the Weapons Kit, so can’t give you a definite answer. However, if you look in the main WeaponsSystem module script, you will find references for getTeam so it must be possible to do what you want. The trick is finding it
local function _defaultGetTeamCallback(player)
return 0
end
function WeaponsSystem.getTeam(player)
local handler = _getTeamCallback or _defaultGetTeamCallback
return handler(player)
end
function WeaponsSystem.playersOnDifferentTeams(player1, player2)
if player1 == player2 or player1 == nil or player2 == nil then
-- This allows players to damage themselves and NPC's
return true
end
local player1Team = WeaponsSystem.getTeam(player1)
local player2Team = WeaponsSystem.getTeam(player2)
return player1Team == 0 or player1Team ~= player2Team
end
local function _defaultGetTeamCallback(player)
return 0
end
So, it is always going to return “0” when tested. Perhaps try putting the teamcheck in that function or earlier in the “function WeaponsSystem.playersOnDifferentTeams(player1, player2)” function. How and where that function is called, again not sure.
Perhaps add a breakpoint in to it and see if it ever gets called.
Thank you, so much for you suggestions and found a way to make it work by expanding on the function WeaponsSystem.playersOnDifferentTeams(player1, player2)
function WeaponsSystem.playersOnDifferentTeams(player1, player2)
local Teams = { -- This is the teams
[1] = "Older",
[2] = "Choas",
}
-- player1 is the one that shooting
--player2 is the one getting shot at
local player1Team = WeaponsSystem.getTeam(player1) -- Gets the players team
local player2Team = WeaponsSystem.getTeam(player2) -- Gets the Enemies team
if player2Team == nil then -- This allows players to damage themselves and NPC's
return 0
end
if tostring(player1Team) == tostring(player2Team) then -- if they're in the same team returns false
print("in the same team")
return false -- When false can't damage entity
end
if tostring(player1Team) ~= tostring(player2Team) then -- if the players not in the same team
print("Not in the same team")
player1.Character.tag.Value = player2.Name ---Set the tag here
return 0 -- 0 lets the player to be able to damage other people that aren't in the same team
end
end
Thank you! I expanded on the function WeaponsSystem.playersOnDifferentTeams(player1, player2) just like you did, but unfortunately for some reason it isn’t working for me, every rig or player i shoot isn’t getting damaged.
It appears to be in the same team when it’s actually not, also i’m not getting damaged by my self so definitely there is something i didn’t catch up.
Can you show the steps you followed to make it work properly?
I modified this function in the WeaponsSystem ModuleScript to keep players on the same team from shooting each other:
function WeaponsSystem.doDamage(target, amount, damageType, dealer, hitInfo, damageData)
if not target or ancestorHasTag(target, "WeaponsSystemIgnore") then
return
end
if IsServer then
if target:IsA("Humanoid") and dealer:IsA("Player") and dealer.Character then
local dealerHumanoid = dealer.Character:FindFirstChildOfClass("Humanoid")
local targetPlayer = Players:GetPlayerFromCharacter(target.Parent)
-- Jaxxon Jargon: added check so players on the same team can't kill each other.
if WeaponsSystem.playersOnDifferentTeams(dealer, targetPlayer) then
if dealerHumanoid and target ~= dealerHumanoid and targetPlayer then
-- Trigger the damage indicator
WeaponData:FireClient(targetPlayer, "HitByOtherPlayer", dealer.Character.HumanoidRootPart.CFrame.Position)
targetPlayer.Character.Humanoid:TakeDamage(amount)
end
end
end
-- NOTE: damageData is a more or less free-form parameter that can be used for passing information from the code that is dealing damage about the cause.
-- .The most obvious usage is extracting icons from the various weapon types (in which case a weapon instance would likely be passed in)
-- ..The default weapons pass in that data
local handler = _damageCallback or _defaultDamageCallback
handler(WeaponsSystem, target, amount, damageType, dealer, hitInfo, damageData)
end
end
You’ll also need to modify the following function:
local function _defaultGetTeamCallback(player)
return player.Team or 0
end