Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

NPC Doesn't Attack a Specific TeamColor?

Asked by 8 years ago

Hello Everybody! My name is IronSpider671 and I am once again back here at ScriptingHelpers, because I seem to have utterly failed. So, I'm making a little game as a side project with NPCs and players fighting each other between two teams (not sure about the names yet but the colors are: Navy blue and Maroon). So, I wrote this little script, bits and pieces taken from tutorials, open source versions of games, and my own Lua knowledge. So, this script works, for the time being. I mean the NPCs run around and shoot every single Humanoid near them. This is my script:

01local larm = script.Parent:FindFirstChild("Left Arm")
02local rarm = script.Parent:FindFirstChild("Right Arm")
03 
04local wanderTarget
05local wanderAngle
06local wanderConeSize = 6
07local maxWanderAngle = 0.75
08 
09function getWanderTarget()
10    math.random(tick())
11    wanderAngle = (math.random() - 0.5) * maxWanderAngle
12    rotatedLookVector = CFrame.Angles(0, wanderAngle, 0) * script.Parent.Torso.CFrame.lookVector
13    return (script.Parent.Torso.Position + wanderConeSize * rotatedLookVector)
14end
15 
View all 72 lines...

But, since my game is team-based, I wanted the NPCs to specifically attack the opposing team (or a specific TeamColor) So, I edited around and tried the NPC to just fire at and move to the torsos of players with the TeamColor, Maroon. This was my script afterwards:

01local larm = script.Parent:FindFirstChild("Left Arm")
02local rarm = script.Parent:FindFirstChild("Right Arm")
03 
04local wanderTarget
05local wanderAngle
06local wanderConeSize = 6
07local maxWanderAngle = 0.75
08 
09function getWanderTarget()
10    math.random(tick())
11    wanderAngle = (math.random() - 0.5) * maxWanderAngle
12    rotatedLookVector = CFrame.Angles(0, wanderAngle, 0) * script.Parent.Torso.CFrame.lookVector
13    return (script.Parent.Torso.Position + wanderConeSize * rotatedLookVector)
14end
15 
View all 76 lines...

After this, well... nothing. The NPC doesn't even move. It just stands there, not doing anything. I'm not sure what I did wrong (perhaps I put the if statement in a wrong location or so) but any help would be much appreciated! -IronSpider671

Answer this question