How can I edit the script to insert a condition that checks for example the torso colour or a value inside the team ai so that it does not damage a team ai? I've already dealt with it killing team members but now i need to change it so it doesn't kill team ais as well. I'm not sure how to identify where to insert the line of code that checks the value inside the character. I think the main problem is that the script checks if it is a player or an ai it is damaging. I think I'm probably inserting the line of code in the wrong place. Here's the main part of the hit script. The script's quite long but I would really appreciate it if anyone could help me and tell me how to identify where to insert the script for future reference when I want to do the same for other weapons.

function CastLightning(character)
	local CreatorPlayer = GetCreator()
	if not CreatorPlayer then
		return
	end
	local humanoid = character:FindFirstChild("Humanoid")
	local torso = character:FindFirstChild("Torso")
	if not humanoid or humanoid.Health == 0 or not torso then
		return
	end
	Spawn(function()
		local ObjectHit = LightningStrike(Part.Position, torso.Position)
		if ObjectHit then
			local HitCharacter = ObjectHit.Parent
			if HitCharacter:IsA("Hat") then
				HitCharacter = HitCharacter.Parent
			end
			local HitHumanoid = HitCharacter:FindFirstChild("Humanoid")
			if not HitHumanoid or HitHumanoid.Health == 0 or HitHumanoid ~= humanoid then
				return
			end
			local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
if Player.TeamColor ~= vPlayer.TeamColor then 
			Functions.UntagHumanoid(humanoid)
			Functions.TagHumanoid(humanoid, CreatorPlayer)
			humanoid:TakeDamage(Damage.Value)
			local TripChance = math.random(1, 999999999999999999999)
			if TripChance == 1 then
				humanoid.Sit = true
				torso.Velocity = (CFrame.new(Part.Position, torso.Position).lookVector * 50)
			end
end
end
	end)
end

function GetPlayersNearby(Radius)
	local Humanoids = {}
	local CreatorPlayer = GetCreator()
	if CreatorPlayer then
		local NegativeRegion = (Part.Position - Vector3.new(Radius, Radius, Radius))
		local PositiveRegion = (Part.Position + Vector3.new(Radius, Radius, Radius))
		local Region = Region3.new(NegativeRegion, PositiveRegion)
		local IgnoreList = {((CreatorPlayer and CreatorPlayer.Character) or nil)}
		for i, v in pairs(Players:GetChildren()) do
			if v:IsA("Player") and v ~= CreatorPlayer and v.Character and v.Character.Parent and Functions.IsTeamMate(CreatorPlayer, v) then
				table.insert(IgnoreList, v.Character)
			end
		end
		local Parts = Functions.GetParts(Region, 500, IgnoreList)
		for i, v in pairs(Parts) do
			local character = v.Parent
			if character:IsA("Hat") then
				character = character.Parent
			end
			local humanoid = character:FindFirstChild("Humanoid")
			local torso = character:FindFirstChild("Torso")
			if humanoid and humanoid.Health > 0 and torso and not Functions.CheckTableForInstance(Humanoids, humanoid) then
				table.insert(Humanoids, humanoid)
			end
		end
	end
	return Humanoids
end

function PartHit(Hit)
	local CreatorPlayer = GetCreator()
	if not Hit or not Hit.Parent or not CreatorPlayer or HitDelay or Part.Velocity.Magnitude < 8 then
		return
	end
	local character = Hit.Parent
	local humanoid = character:FindFirstChild("Humanoid")
	if not humanoid or humanoid.Health == 0 then
		return
	end
	local player = Players:GetPlayerFromCharacter(character)
	if player and (CreatorPlayer == player or Functions.IsTeamMate(CreatorPlayer, player)) then
		return
	end
	HitDelay = true
	Functions.UntagHumanoid(humanoid)
	Functions.TagHumanoid(humanoid, CreatorPlayer)
	humanoid:TakeDamage((Damage.Value * 2.5))
	wait(0.2)
	HitDelay = false
end

3 comments

3

Please use a code block.

0

As wfvj014 mentioned, this is unreadable without a code block...

0

sorry new to this