Anti-teamkill not working

So, when the player fires the gun, it’s suppose to check if the person the player’s shooting is on their team or not. If they’re not, then it damages them, if not, nothing happens. Doesn’t work for some reason.

local target = Mouse.Target
if target and target.Parent:FindFirstChild("Humanoid") then
    if game.Players:GetPlayerFromCharacter(target.Parent).TeamColor == game.Players.LocalPlayer.TeamColor then
	    --nothing
	else
		--damage the player
	end
end

try this:

local target = Mouse.Target
if target and target.Parent:FindFirstChild("Humanoid") then
	if game.Players:GetPlayerFromCharacter(target.Parent).TeamColor ~= game.Players.LocalPlayer.TeamColor then
		print("plr not on team damage")
	else
		print("attempted to shoot teamaate.")
	end
end
1 Like

“attempt to index nil with TeamColor”

Is this script a local script?

Yeah it is. Because the gun gets the player’s input and passes it onto the server.

You should send the mouse target over to the server so you can do a check using the “Team” property of a player(not on client because “Team” isn’t replicated.).

Do the check on the server.

3 Likes