How to edit my gun gun script in order to make it won't kill my teammates?
I'm trying to make a gun game, but my gun can kill my teammates. How can I edit this to avoid that?
(Sorry if it looks really messy and really unoptimized, I'm really new to Roblox scripting.)
Code:
001 | local function createBullet(target) |
002 | local bullet = tool.Bullet:Clone() |
003 | table.insert(ignoreTable, bullet) |
004 | bullet.Parent = workspace |
005 | bullet.CFrame = CFrame.new(muzzle.CFrame.p, target) |
006 | bullet.Trail.Enabled = true |
009 | bullet.Transparency = 0 |
010 | local missionAccomplished = false |
012 | for i = 1 , numSegments do |
013 | if not missionAccomplished then |
014 | local equation = bullet.CFrame * CFrame.new( 0 , 0 , -segmentLength) * CFrame.Angles(dropAngle, 0 , 0 ) |
015 | local ray = Ray.new(bullet.Position, (equation.p - bullet.Position).unit * segmentLength) |
016 | local part, pos, normal, material = workspace:FindPartOnRayWithIgnoreList(ray, ignoreTable) |
017 | if part and part.Parent:FindFirstChild( "Humanoid" ) then |
018 | missionAccomplished = true |
019 | bullet.HitSound:Play() |
020 | hitEvent:FireClient(game.Players:GetPlayerFromCharacter(tool.Parent)) |
021 | local hum = part.Parent.Humanoid |
022 | if part.Name = = "Head" and configs.headshotInstakill = = true then |
023 | local neck = part.Parent:FindFirstChild( "Neck" , true ) |
026 | elseif part.Name = = "Head" then |
027 | hum:TakeDamage(headDamage) |
028 | elseif part.Name = = "Torso" or part.Name = = "UpperTorso" or part.Name = = "LowerTorso" then |
029 | hum:TakeDamage(torsoDamage) |
031 | hum:TakeDamage(otherDamage) |
035 | bullet.CFrame = CFrame.new(pos, equation.p) |
036 | local weld = Instance.new( "Weld" , bullet) |
037 | weld.C 0 = bullet.CFrame:inverse() * part.CFrame |
040 | bullet.Anchored = false |
042 | bullet.Transparency = 1 |
043 | if configs.blood = = true then |
044 | bullet.EffectAttachment.BloodEmitter:Emit( 20 ) |
047 | for ii, v in pairs (ignoreTable) do |
049 | table.remove(ignoreTable, ii) |
054 | missionAccomplished = true |
055 | bullet.CFrame = CFrame.new(pos, equation.p) |
057 | bullet.Transparency = 1 |
058 | bullet.ThudSound:Play() |
059 | if hitParticles and part.Transparency and part.Transparency < 1 then |
060 | if part.ClassName ~ = "Terrain" then |
061 | bullet.EffectAttachment.DebrisEmitter.Color = ColorSequence.new(part.Color) |
062 | elseif material = = Enum.Material.Grass |
063 | or material = = Enum.Material.LeafyGrass |
064 | or material = = Enum.Material.Ground |
065 | or material = = Enum.Material.Mud |
066 | or material = = Enum.Material.Cobblestone then |
067 | bullet.EffectAttachment.DebrisEmitter.Color = ColorSequence.new(Color 3. new( 61 / 255 , 51 / 255 , 44 / 255 )) |
068 | elseif material = = Enum.Material.Asphalt |
069 | or material = = Enum.Material.Concrete |
070 | or material = = Enum.Material.Pavement |
071 | or material = = Enum.Material.Slate then |
072 | bullet.EffectAttachment.DebrisEmitter.Color = ColorSequence.new(Color 3. new( 100 / 255 , 99 / 255 , 93 / 255 )) |
073 | elseif material = = Enum.Material.Limestone |
074 | or material = = Enum.Material.Sand |
075 | or material = = Enum.Material.WoodPlanks then |
076 | bullet.EffectAttachment.DebrisEmitter.Color = ColorSequence.new(Color 3. new( 172 / 255 , 153 / 255 , 116 / 255 )) |
077 | elseif material = = Enum.Material.Brick or material = = Enum.Material.Sandstone then |
078 | bullet.EffectAttachment.DebrisEmitter.Color = ColorSequence.new(Color 3. new( 165 / 255 , 114 / 255 , 95 / 255 )) |
079 | elseif material = = Enum.Material.Rock then |
080 | bullet.EffectAttachment.DebrisEmitter.Color = ColorSequence.new(Color 3. new( 93 / 255 , 96 / 255 , 103 / 255 )) |
081 | elseif material = = Enum.Material.Basalt or material = = Enum.Material.CrackedLava then |
082 | bullet.EffectAttachment.DebrisEmitter.Color = ColorSequence.new(Color 3. new( 22 / 255 , 11 / 255 , 10 / 255 )) |
083 | elseif material = = Enum.Material.Salt or material = = Enum.Material.Snow then |
084 | bullet.EffectAttachment.DebrisEmitter.Color = ColorSequence.new(Color 3. new( 190 / 255 , 180 / 255 , 190 / 255 )) |
085 | elseif material = = Enum.Material.Glacier or material = = Enum.Material.Ice then |
086 | bullet.EffectAttachment.DebrisEmitter.Color = ColorSequence.new(Color 3. new( 162 / 255 , 194 / 255 , 217 / 255 )) |
088 | bullet.EffectAttachment.DebrisEmitter:Emit( 10 ) |
091 | for ii, v in pairs (ignoreTable) do |
093 | table.remove(ignoreTable, ii) |
098 | bullet.CFrame = equation |
100 | wait(waitBetweenSegments) |
end