Why is my npc only targeting R6 players? [Solved]
Asked by
6 years ago Edited 6 years ago
Hey everyone, I am using the shade from the Forbidden Box Gear and it currently is only going after R6 players, not R15. I realize that R15 players don't have a torso so I've changed line 258 from: local t=h.Parent:FindFirstChild("Torso")
to local t=h.Parent:FindFirstChild("UpperTorso")
, but it still seems to be going after R6 players only. I've used the search tool to find all the "Torsos" within the script but the other ones seem to be related to the shade's torso, not the torso of other players.
022 | function raycast(spos,vec,currentdist) |
023 | local hit 2 ,pos 2 = game.Workspace:FindPartOnRay(Ray.new(spos+(vec*. 01 ),vec*currentdist),sp) |
024 | if hit 2 ~ = nil and pos 2 then |
025 | if hit 2. Transparency> = . 8 or hit 2. Name = = "Handle" or string.sub(hit 2. Name, 1 , 6 ) = = "Effect" then |
026 | local currentdist = currentdist-(pos 2 -spos).magnitude |
027 | return raycast(pos 2 ,vec,currentdist) |
033 | function waitForChild(parent,childName) |
034 | local child = parent:findFirstChild(childName) |
035 | if child then return child end |
037 | child = parent.ChildAdded:wait() |
038 | if child.Name = = childName then return child end |
046 | local Torso = waitForChild(sp, "Torso" ) |
047 | local Head = waitForChild(sp, "Head" ) |
048 | local RightShoulder = waitForChild(Torso, "Right Shoulder" ) |
049 | local LeftShoulder = waitForChild(Torso, "Left Shoulder" ) |
050 | local RightHip = waitForChild(Torso, "Right Hip" ) |
051 | local LeftHip = waitForChild(Torso, "Left Hip" ) |
052 | local Neck = waitForChild(Torso, "Neck" ) |
053 | local Humanoid = waitForChild(sp, "Humanoid" ) |
055 | local hitsound = waitForChild(Torso, "HitSound" ) |
058 | waitForChild(Torso, "Ghost1Sound" ), |
059 | waitForChild(Torso, "Ghost2Sound" ), |
065 | local regenscript = waitForChild(sp, "HealthRegenerationScript" ) |
066 | regenscript.Disabled = false |
068 | Humanoid.WalkSpeed = wonderspeed |
074 | function onRunning(speed) |
090 | function onGettingUp() |
096 | function onFallingDown() |
102 | function onPlatformStanding() |
103 | pose = "PlatformStanding" |
107 | RightShoulder.MaxVelocity = 0.5 |
108 | LeftShoulder.MaxVelocity = 0.5 |
109 | RightShoulder.DesiredAngle = 3.14 |
110 | LeftShoulder.DesiredAngle = - 3.14 |
111 | RightHip.DesiredAngle = 0 |
112 | LeftHip.DesiredAngle = 0 |
115 | function moveFreeFall() |
116 | RightShoulder.MaxVelocity = 0.5 |
117 | LeftShoulder.MaxVelocity = 0.5 |
118 | RightShoulder.DesiredAngle = 3.14 |
119 | LeftShoulder.DesiredAngle = - 3.14 |
120 | RightHip.DesiredAngle = 0 |
121 | LeftHip.DesiredAngle = 0 |
125 | RightShoulder.MaxVelocity = 0.15 |
126 | LeftShoulder.MaxVelocity = 0.15 |
127 | RightShoulder.DesiredAngle = 3.14 / 2 |
128 | LeftShoulder.DesiredAngle = - 3.14 / 2 |
129 | RightHip.DesiredAngle = 3.14 / 2 |
130 | LeftHip.DesiredAngle = - 3.14 / 2 |
133 | function animate(time) |
136 | if (pose = = "Jumping" ) then |
140 | if (pose = = "FreeFall" ) then |
144 | if (pose = = "Seated" ) then |
149 | if (pose = = "Running" ) then |
150 | RightShoulder.MaxVelocity = 0.15 |
151 | LeftShoulder.MaxVelocity = 0.15 |
154 | elseif (pose = = "Climbing" ) then |
155 | RightShoulder.MaxVelocity = 0.5 |
156 | LeftShoulder.MaxVelocity = 0.5 |
164 | desiredAngle = amplitude * math.sin(time*frequency) |
165 | if not chasing and frequency = = 9 then |
169 | RightShoulder.DesiredAngle = math.pi/ 2 |
170 | LeftShoulder.DesiredAngle = -math.pi/ 2 |
171 | RightHip.DesiredAngle = -desiredAngle* 2 |
172 | LeftHip.DesiredAngle = -desiredAngle* 2 |
174 | RightShoulder.DesiredAngle = desiredAngle + climbFudge |
175 | LeftShoulder.DesiredAngle = desiredAngle - climbFudge |
176 | RightHip.DesiredAngle = -desiredAngle |
177 | LeftHip.DesiredAngle = -desiredAngle |
182 | function attack(time,attackpos) |
183 | if time-lastattack> = 1 then |
184 | local hit,pos = raycast(Torso.Position,(attackpos-Torso.Position).unit,attackrange) |
185 | if hit and hit.Parent~ = nil and hit.Parent.Name~ = sp.Name then |
186 | local h = hit.Parent:FindFirstChild( "Humanoid" ) |
188 | local creator = sp:FindFirstChild( "creator" ) |
190 | if creator.Value~ = nil then |
191 | if creator.Value~ = game.Players:GetPlayerFromCharacter(h.Parent) then |
192 | for i,oldtag in ipairs (h:GetChildren()) do |
193 | if oldtag.Name = = "creator" then |
197 | creator:clone().Parent = h |
204 | hitsound.Volume = . 5 +(. 5 *math.random()) |
205 | hitsound.Pitch = . 5 +math.random() |
207 | if RightShoulder and LeftShoulder then |
208 | RightShoulder.CurrentAngle = 0 |
209 | LeftShoulder.CurrentAngle = 0 |
218 | Humanoid.Died:connect(onDied) |
219 | Humanoid.Running:connect(onRunning) |
220 | Humanoid.Jumping:connect(onJumping) |
221 | Humanoid.Climbing:connect(onClimbing) |
222 | Humanoid.GettingUp:connect(onGettingUp) |
223 | Humanoid.FreeFalling:connect(onFreeFall) |
224 | Humanoid.FallingDown:connect(onFallingDown) |
225 | Humanoid.Seated:connect(onSeated) |
226 | Humanoid.PlatformStanding:connect(onPlatformStanding) |
229 | function populatehumanoids(mdl) |
230 | if mdl.ClassName = = "Humanoid" then |
231 | table.insert(humanoids,mdl) |
233 | for i 2 ,mdl 2 in ipairs (mdl:GetChildren()) do |
234 | populatehumanoids(mdl 2 ) |
238 | function playsound(time) |
239 | nextsound = time+ 5 +(math.random()* 5 ) |
240 | local randomsound = sounds [ math.random( 1 ,#sounds) ] |
241 | randomsound.Volume = . 5 +(. 5 *math.random()) |
242 | randomsound.Pitch = . 5 +(. 5 *math.random()) |
246 | while sp.Parent~ = nil and Humanoid and Humanoid.Parent~ = nil and Humanoid.Health> 0 and Torso and Head and Torso~ = nil and Torso.Parent~ = nil do |
247 | local _,time = wait( 1 / 3 ) |
249 | populatehumanoids(game.Workspace) |
251 | closestdist = sightrange |
252 | local creator = sp:FindFirstChild( "creator" ) |
253 | for i,h in ipairs (humanoids) do |
254 | if h and h.Parent~ = nil then |
255 | if h.Health> 0 and h.Parent.Name~ = sp.Name and h.Parent~ = sp then |
256 | local plr = game.Players:GetPlayerFromCharacter(h.Parent) |
257 | if creator = = nil or plr = = nil or creator.Value~ = plr then |
258 | local t = h.Parent:FindFirstChild( "UpperTorso" ) |
260 | local dist = (t.Position-Torso.Position).magnitude |
261 | if dist<closestdist then |
270 | if closesttarget~ = nil then |
274 | Humanoid.WalkSpeed = runspeed |
276 | Humanoid:MoveTo(closesttarget.Position+(Vector 3. new( 1 , 1 , 1 )*(variance*((math.random()* 2 )- 1 ))),closesttarget) |
277 | if math.random()<. 5 then |
278 | attack(time,closesttarget.Position) |
283 | Humanoid.WalkSpeed = wonderspeed |
285 | if time>nextrandom then |
286 | nextrandom = time+ 3 +(math.random()* 5 ) |
287 | local randompos = Torso.Position+((Vector 3. new( 1 , 1 , 1 )*math.random()-Vector 3. new(. 5 ,. 5 ,. 5 ))* 40 ) |
288 | Humanoid:MoveTo(randompos,game.Workspace.Terrain) |
291 | if time>nextsound then |
294 | if time>nextjump then |
295 | nextjump = time+ 7 +(math.random()* 5 ) |
301 | for i,v in ipairs (sp:GetChildren()) do |
302 | if v.className = = "Part" then |
Thanks for your help.