Anti Team Kill Script not Working?

Hi I’m making a game for my online class and it is a fighting game.

I’m trying t add Anti-Team Kill (ATK) and the script will not work!

I’m also using the FE melee kit (2021) (Because I’m bad at coding)

And i need help.

This is he code for the ATK.

function onHumanoidDied(humanoid, player)
local killer = getKillerOfHumanoidIfStillInGame(humanoid)
if (killer ~= nil) then
handleTKs(player, killer)
end
end

function onPlayerRespawn(property, player)

if property == "Character" and player.Character ~= nil then
	local humanoid = player.Character.Humanoid
		local p = player
		local h = humanoid
		humanoid.Died:connect(function() onHumanoidDied(h, p) end )
end

end

function getKillerOfHumanoidIfStillInGame(humanoid)

local tag = humanoid:findFirstChild("creator")


if tag ~= nil then
	local killer = tag.Value
	if killer.Parent ~= nil then 
		return killer
	end
end

return nil

end

function handleTKs(player, killer)
if (killer.TeamColor == player.TeamColor) then
killer.Character.Humanoid.Health = 0
end
end

function onPlayerEntered(newPlayer)
while true do
if newPlayer.Character ~= nil then break end
wait(3)
end

	local humanoid = newPlayer.Character.Humanoid

	humanoid.Died:connect(function() onHumanoidDied(humanoid, newPlayer) end )
	newPlayer.Changed:connect(function(property) onPlayerRespawn(property, newPlayer) end )

end

game.Players.ChildAdded:connect(onPlayerEntered)

Is there a problem?

This is what it looks like in game.

Please help!

(P.S I’m new to this coding language)

Sorry about the weird part of the code. I’m new to the Dev Forums

1 Like

Why don’t you prevent damage against teammates altogether?

1 Like

That’s what I’m trying to do ok?

Firstly, this code needs to be organized and made much better, as well as the post:

This should be replaced with humanoid.Died:Connect(function(onHumanoidDied)

And a lot of more, but the goal is to make it work. I can’t give you a complete script, but I can tell you how to make it and give you some sources in which you can learn about each thing.

It’s really difficult to control if the gun can make damage or not if you don’t make it, but it’s actually really simple, you just need to know how to use a few things like Mouse properties, Tool events, etc. Then, for example if the Mouse target is a teammate, just force it to not take damage, and if it is on any other team, it can damage. To do that you will need to at least know about client / server side, Players Service and Teams Service.

Hopefully it helps.

Sources:

https://developer.roblox.com/en-us/api-reference/class/Players

https://developer.roblox.com/en-us/api-reference/property/Player/Team