Why won't bot target team player?
Asked by
4 years ago Edited 4 years ago
I am trying to get a bot to target a player on a specific team.
The output prints test2 with no errors.
Please help me fix lines 51 - 57.
011 | t.Humanoid.Died:wait() |
012 | script.Parent.Handle:Destroy() |
013 | local waiting = math.random( 3 , 7 ) |
019 | local cf = { CFrame.new(. 8 ,. 5 ,. 4 )*CFrame.Angles(math.rad( 270 ),math.rad( 40 ), 0 ),CFrame.new(- 1.2 , 0.5 , 0.4 )*CFrame.Angles(math.rad( 270 ),math.rad(- 5 ), 0 ) } |
020 | local c = require(game.ReplicatedStorage:WaitForChild( "LoadLibrary" ):WaitForChild( "RbxUtility" )).Create |
021 | local b 1 = c 'Part' { TopSurface = 0 ;BottomSurface = 0 ;Anchored = true ;CanCollide = false ;BrickColor = BrickColor.new( "Cool yellow" );Size = Vector 3. new(. 2 ,. 2 , 1 );c 'SpecialMesh' { MeshType = 6 ;Scale = Vector 3. new(. 2 ,. 2 , 1 ) } } ;Transparency = . 5 |
023 | b 1. Name,b 2. Name = '1' , '2' |
024 | local mov = c 'Part' { Transparency = 1 ;CanCollide = false ;Parent = t;Anchored = true } |
025 | local h = t:WaitForChild 'Handle' |
026 | local function reload(boo) |
027 | if (boo and ammo~ = 30 ) or ammo = = 0 then |
044 | local dis,pl = range, nil |
045 | for _,v in ipairs (game.Players:GetPlayers()) do |
046 | if v.Character and v.Character:FindFirstChild 'Humanoid' and v:DistanceFromCharacter(h.Position)<dis then |
047 | dis,pl = v:DistanceFromCharacter(h.Position),v |
051 | if pl.TeamColor = = "Lime green" then |
053 | return pl.Character:GetModelCFrame(),dis,CFrame.new(pl.Character.Humanoid.WalkToPoint).lookVector |
065 | while not w do wait(. 1 ) end |
066 | for i = 1 ,math.random( 4 , 9 ) do |
072 | while wait(math.random( 2 , 7 )/ 10 ) do |
074 | if n and math.random( 1 , 3 ) = = 2 or not n then |
075 | mov.CFrame = t.Torso.CFrame+t.Torso.CFrame.lookVector*Vector 3. new(math.random(- 25 , 25 ), 0 ,math.random(- 25 , 25 )) |
077 | mov.CFrame = n+Vector 3. new((math.random( 1 , 2 ) = = 1 and 1 or - 1 )*math.random( 25 , 50 ), 0 ,(math.random( 1 , 2 ) = = 1 and 1 or - 1 )*math.random( 25 , 50 )) |
080 | t.Humanoid:MoveTo(mov.Position,mov) |
084 | local n,mag,hum = near() |
089 | local dir = h.Position-n |
090 | local tst,_ = workspace:FindPartOnRay(Ray.new(t.Torso.Position,(n-t.Torso.Position).Unit* 999 ),t) |
091 | local aim = n+Vector 3. new(math.random(-mag*. 015 ,mag*. 015 ),math.random(-mag*. 015 ,mag*. 015 ),math.random(-mag*. 015 ,mag*. 015 ))*( 2 +math.random())+hum |
092 | if tst and tst.Parent and game.Players:GetPlayerFromCharacter(tst.Parent) then |
095 | local par,pos = workspace:FindPartOnRay(Ray.new(h.Position,(aim-h.Position).Unit* 999 ),t) |
097 | local h = par.Parent:FindFirstChild 'Humanoid' or par.Parent.Parent:FindFirstChild 'Humanoid' |
098 | if h and h.Health- 10 > 0 then |
102 | h.Parent:BreakJoints() |
106 | mag = (h.Position-pos).magnitude |
107 | b 1. Parent,b 2. Parent = t,t |
108 | b 1. CFrame,b 2. CFrame = CFrame.new(h.Position:Lerp(pos,. 375 ),pos),CFrame.new(pos:Lerp(h.Position,. 125 ),h.Position) |
109 | b 1. Mesh.Scale,b 2. Mesh.Scale = Vector 3. new(. 2 ,. 2 ,mag*. 75 ),Vector 3. new(. 2 ,. 2 ,mag/ 4 ) |
110 | Delay(. 03 , function ()b 1. Parent = nil wait(. 03 )b 2. Parent = nil end ) |