Why does this code not work and how would i check the players team?
01 | local part = script.Parent |
02 | local Shot = script.Parent.Parent.ShotPart |
08 | local rep = game.ReplicatedStorage:WaitForChild( "TeamEvent" ) |
12 | local lookvector = part.CFrame.LookVector |
15 | for i,v in pairs (game.Workspace:getChildren()) do |
16 | local player = game:GetService( "Players" ) |
17 | local maths = math.random( 1 , 4 ) |
18 | local hum = v:FindFirstChild( "Humanoid" ) |
19 | local ignore = v:FindFirstChild( "Pirate" ) |
20 | local ignore 1 = v:FindFirstChild( "Navy" ) |
21 | if script.Parent.Neutral = = true and script.Parent.Cap.Value = = BrickColor.new( "Medium stone grey" ) then |
22 | local targets = v:FindFirstChild( "Torso" ) |
23 | if hum and targets and hum.Health > 0 then |
24 | if (targets.Position - Shot.Position).Magnitude < range then |
25 | local ray = Ray.new(Shot.Position,(targets.Position - Shot.Position).Unit * range) |
26 | local hit, Pos = game.Workspace:FindPartOnRayWithIgnoreList(ray, { Shot, part } ) |
27 | if hit = = targets then |
31 | print ( "some thing is in the way" ) |
35 | elseif script.Parent.Neutral = = false and script.Parent.Cap.Value = = BrickColor.new( "Lapis" ) then |
36 | local targets = v:FindFirstChild( "Pirate" ) |
37 | if hum and targets and hum.Health > 0 then |
38 | if (targets.Position - Shot.Position).Magnitude < range then |
39 | local ray = Ray.new(Shot.Position,(targets.Position - Shot.Position).Unit * range) |
40 | local hit, Pos = game.Workspace:FindPartOnRayWithIgnoreList(ray, { Shot, part } ) |
41 | if hit = = targets then |
49 | elseif script.Parent.Neutral = = false and script.Parent.Cap.Value = = BrickColor.new( "Really black" ) then |
50 | local targets = v:FindFirstChild( "Navy" ) |
51 | if hum and targets and hum.Health > 0 then |
52 | if (targets.Position - Shot.Position).Magnitude < range then |
53 | local ray = Ray.new(Shot.Position,(targets.Position - Shot.Position).Unit * range) |
54 | local hit, Pos = game.Workspace:FindPartOnRayWithIgnoreList(ray, { Shot, part } ) |
55 | if hit = = targets then |
66 | local targets = target |
67 | part.CFrame = CFrame.new(part.Position, targets.Position) |
68 | local ball = game.ServerStorage:WaitForChild( "Ball" ) |
69 | local cloneball = ball:Clone() |
70 | cloneball.Position = Shot.Position |
71 | cloneball.Parent = game.Workspace |
72 | cloneball.Velocity = part.CFrame.LookVector*speed |
73 | cloneball.Touched:Connect( function (ObjectHit) |
74 | local hum = ObjectHit:FindFirstChild( "Humanoid" ) |
75 | local explosion = Instance.new( "Explosion" ) |
76 | explosion.BlastRadius = 10 |
77 | explosion.ExplosionType = Enum.ExplosionType.Craters |
78 | explosion.Position = ObjectHit.Position |
79 | explosion.Parent = game.Workspace |
how do i make it not to shoot team mates instead shoot enemy's rn it wont work and i dont know what to do and if there is a more better way of doing this
01 | elseif script.Parent.Neutral = = false and script.Parent.Cap.Value = = BrickColor.new( "Lapis" ) then |
02 | local targets = v:FindFirstChild( "Pirate" ) |
03 | if hum and targets and hum.Health > 0 then |
04 | if (targets.Position - Shot.Position).Magnitude < range then |
05 | local ray = Ray.new(Shot.Position,(targets.Position - Shot.Position).Unit * range) |
06 | local hit, Pos = game.Workspace:FindPartOnRayWithIgnoreList(ray, { Shot, part } ) |
07 | if hit = = targets then |