my script:
local figure = script.Parent
local Tool = script.Parent.PaintballGun
local reload = .5
function modechange()
local mode = figure.mode
if mode.Value == 1 then reload = .5
elseif mode.Value == 2 then reload = 5
elseif mode.Value == 3 then reload = 1.5
elseif mode.Value == 4 then reload = 10 end
end
function findNearestTorso()
local targetTorso = nil
local distance = 500
local list = game.Workspace:children()
for i = 1, #list do
local listTorso = list[i]:FindFirstChild("Torso")
if listTorso ~= nil and list[i]:FindFirstChild("Humanoid") ~= nil and list[i] ~= figure then
if (listTorso.Position - figure.Torso.Position).magnitude < distance then
distance = (listTorso.Position - figure.Torso.Position).magnitude
targetTorso = listTorso
end
end
end
list = nil
return targetTorso
end
function fire(v)
Tool.Handle.Fire:play()
local torso = figure:FindFirstChild("Torso")
local missile = Instance.new("Part")
local spawnPos = figure.Head.Position
local sp = figure.Torso.CFrame.lookVector
spawnPos = spawnPos + (v * 3)
missile.Position = spawnPos
missile.Size = Vector3.new(1, 1, 1)
if figure.mode.Value == 1 then missile.Velocity = v * 160
elseif figure.mode.Value == 3 then missile.Velocity = Vector3.new(v.x * math.random(80, 100), v.y * math.random(80, 100), v.z * math.random(80, 100))
elseif figure.mode.Value == 2 then missile.Velocity = v * 550 end
missile.Shape = 0
missile.BottomSurface = 0
missile.TopSurface = 0
missile.Name = "Paintball"
missile.Elasticity = 0
missile.Reflectance = 0
missile.BrickColor = BrickColor.Random()
missile.Friction = .9
missile.CanCollide = false
local force = Instance.new("BodyForce")
force.force = Vector3.new(0, 90, 0)
force.Parent = missile
Tool.BrickCleanup:clone().Parent = missile
if figure.mode.Value == 2 then
local new_script = Tool.Paintball2:clone()
new_script.Disabled = false
new_script.Parent = missile
elseif figure.mode.Value == 1 or figure.mode.Value == 3 then
local new_script = Tool.Paintball:clone()
new_script.Disabled = false
new_script.Parent = missile
end
local creator_tag = Instance.new("ObjectValue")
creator_tag.Value = figure
creator_tag.Name = "creator"
creator_tag.Parent = missile
missile.Parent = game.Workspace
if figure.mode.Value == 3 and torso ~= nil then
for i = 1, 2 do
bMissile = missile:clone()
bMissile.Velocity = Vector3.new(v.x * math.random(80, 100), v.y * math.random(80, 100), v.z * math.random(80, 100))
if i == 1 then bMissile.CFrame = bMissile.CFrame - (torso.CFrame.lookVector * 1.5) + Vector3.new(0, .5)
else bMissile.CFrame = bMissile.CFrame + (torso.CFrame.lookVector * 1.25) + Vector3.new(0, .75, 0) end
bMissile.Parent = game.Workspace
end
end
end
function grenade(v)
local head, torso, player = find("Head", figure), find("Torso", figure)
if head == nil or torso == nil then return end
local spawnPos = head.Position + (v * 4)
local gnade = ball:clone()
gnade.CanCollide = true
gnade.CFrame = CFrame.new(spawnPos)
gnade.Velocity = v * 60 + Vector3.new(0, 45, 0)
local bc = Instance.new("BrickColorValue")
bc.Value = torso.BrickColor
bc.Name = "BCValue"
bc.Parent = gnade
local exScript = Tool.Grenade:clone()
exScript.Disabled = false
exScript.Parent = gnade
gnade.Parent = game.Workspace
end
while script.Parent.Humanoid.Health > 0 do
local torso = figure:FindFirstChild("Torso")
-- local player = game.Players:children()
local target = findNearestTorso() -- nil
-- if #player > 0 and math.random(1, 3) == 1 then target = player[math.random(1, #player)] else target = findATorso() end
if target ~= nil and torso ~= nil then
-- if target.className == "Player" then target = target.Character:FindFirstChild("Torso") end
-- if target ~= nil then
local pos = target.Position
local dir = (pos - torso.Position).magnitude
if dir < 130 then pos = pos + (target.CFrame.lookVector * (dir/math.random(25, 50))) end
if dir >= 130 then figure.mode.Value = 2 pos = pos + Vector3.new(0, math.random(1, 2), 0)
elseif dir < 130 and dir >= 50 then figure.mode.Value = 1 pos = pos + Vector3.new(0, (dir/75) * math.random(1, 4), 0)
elseif dir < 50 then figure.mode.Value = 3 pos = pos + Vector3.new(0, (dir/75) * math.random(1, 4), 0)
else figure.mode.Value = 4 end
modechange()
local lookAt = (pos - torso.Position).unit
if figure.mode.Value == 4 then fireNade(lookAt) elseif figure.mode.Value < 4 then fire(lookAt) end
-- end
end
wait(reload + math.random() * 1.5)
end
i want to make it so it shoots enemy team only not any player. so it does not shoot its own team mate it only shoots at enemy.

4 comments
You'll need to make an "if" statement to check the player's TeamColor before firing.
can you plz fix your formatting
Edited to add code formatting
^^^