Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Anti-Team killing section help?

I'm trying to convert this section into an Anti-TK one that works in FE. I'd like the script to not apply damage to teammates but to players that aren't in the same team. If anyone could help me make this work, I'd be glad.

Original section

	while PierceAvailable >= 0 do
		local Hit,EndPos = RayCast(Start,Direction,5000,Character)
		if not Module.ExplosiveEnabled then
			if Hit and Hit.Parent then
				local TargetHumanoid = Hit.Parent:FindFirstChild("Humanoid")
				local TargetTorso = Hit.Parent:FindFirstChild("Torso")
				--local TargetTEAM = Hit.Parent:FindFirstChild("TEAM")
				if TargetHumanoid and TargetHumanoid.Health > 0 and TargetTorso then
					--if TargetTEAM and TargetTEAM.Value ~= TEAM.Value then
						InflictTarget:FireServer(TargetHumanoid,
												TargetTorso,
												(Hit.Name == "Head" and Module.HeadshotEnabled) and Module.BaseDamage * Module.HeadshotDamageMultiplier or Module.BaseDamage,
												Direction,
												Module.Knockback,
												Module.Lifesteal,
												Module.FlamingBullet)
						PiercedHumanoid[TargetHumanoid] = true
					--end
				else
					PierceAvailable = 0
				end
			end

Attempted edit

	while PierceAvailable >= 0 do
		local Hit,EndPos = RayCast(Start,Direction,5000,Character)
		if not Module.ExplosiveEnabled then
			if Hit and Hit.Parent then
				local TargetHumanoid = Hit.Parent:FindFirstChild("Humanoid")
				local TargetTorso = Hit.Parent:FindFirstChild("Torso")
				--local TargetTEAM = Hit.Parent:FindFirstChild("TEAM")
				if TargetHumanoid and TargetHumanoid.Health > 0 and TargetTorso and Player.TeamColor == "Bright red" then
					--if TargetTEAM and TargetTEAM.Value ~= TEAM.Value then
					
				elseif TargetHumanoid and TargetHumanoid.Health > 0 and TargetTorso then
						InflictTarget:FireServer(TargetHumanoid,
												TargetTorso,
												(Hit.Name == "Head" and Module.HeadshotEnabled) and Module.BaseDamage * Module.HeadshotDamageMultiplier or Module.BaseDamage,
												Direction,
												Module.Knockback,
												Module.Lifesteal,
												Module.FlamingBullet)
						PiercedHumanoid[TargetHumanoid] = true
					--end
				else
					PierceAvailable = 0
				end
			end

1 answer

✓ Accepted answer
if Hit and Hit.Parent then
	local TargetHumanoid = Hit.Parent:FindFirstChild("Humanoid")
	local TargetTorso = Hit.Parent:FindFirstChild("Torso")
	if TargetHumanoid and TargetHumanoid.Health > 0 and TargetTorso then
		-- Get the hit player
		local hitPlayer = game.Players:GetPlayerFromCharacter(TargetHumanoid.Parent)
		-- Check if the local player and the hit player are on different teams. If so, do damage
		if hitPlayer and game.Players.LocalPlayer.Team ~= hitPlayer.Team then
			-- Damage code here
		end
	end
end

1 comment

0

I love you.

This discussion is preserved as it was. New answers, comments, and votes are closed.