Help fixing my anti team kill serverscript

I need help fixing my anti team kill script inside of my tool it is a serverscript
it works it’s just not finding the teams everything prints fine but i still damage my own teammate… can someone help?

			local teams = game:GetService("Teams"):GetTeams()
				for _, team in pairs(teams) do
				local players = team:GetPlayers()
				if game.Teams.Empire then
				local Character = players
				EnemyHumanoid:TakeDamage(Tool.Values.Damage.Value)
				print("EnemyFound")
				if game.Teams.Republic then
				local Character = players
				EnemyHumanoid:TakeDamage(Tool.Values.Damage.Value == 0)
				print("Teammate")	
				end
				end
				
				game.ReplicatedStorage.RemoteEvents.Music:FireClient(player)
end
			end		
			
		end)

1 Like

I believe the root of the problem is that you aren’t checking the enemy’s team. You go through all of the teams but don’t check the enemy’s team. It would help if I could see where you define “EnemyHumanoid”, but this is the best I can provide with the current information:

if game.Players:GetPlayerFromCharacter(EnemyHumanoid.Parent).Team == game.Teams.Empire then
    EnemyHumanoid:TakeDamage(Tool.Values.Damage.Value)
end

Also, only use this for the tools of the “Republic” team (it won’t work and you will only be able to damage teammates otherwise)

I will give it a try and let you know if it don’t work

THANK YOU SO MUCH I been stressing soooo much lol in studio by anychance i can message you sometimes for help?

Yeah, sure, I’m not going to promise that I’ll be on and able to answer all the time, but if I am, I’ll definitely try to help :slightly_smiling_face:

quick question what if i wanna use that same tool to switch teams and use it on the empire?

Simply switch the team requirement to game.Teams.Republic.

if game.Players:GetPlayerFromCharacter(EnemyHumanoid.Parent).Team == game.Teams.Republic then
    EnemyHumanoid:TakeDamage(Tool.Values.Damage.Value)
end
1 Like

Alright I figured it would be that

1 Like

Remove the EnemyHumanoid:TakeDamage line in the “Teammate” one.

1 Like

what would i put that one with?

Hey how would I let it attack a npc and that team? would it be nvm this won’t work how would i do it?

 if game.Players:GetPlayerFromCharacter(EnemyHumanoid.Parent).Team == game.Teams.Empire 
then
  EnemyHumanoid:TakeDamage(Tool.Values.Damage.Value)
 if not game.Players:GetPlayerFromCharacter(EnemyHumanoid.Parent).Team == 
 game.Teams.Empire then
   EnemyHumanoid:TakeDamage(Tool.Values.Damage.Value) 
 end