|
| 22 Mar 2015 12:20 AM |
This is what it is supposed to do: Once the Random walking character gets hurt then he equips he sword from lighting and follows you. Right now he doesnt get the sword equipped and he doesnt follow anybody. He just walks around -_-
if game.Workspace.Guy.Humanoid.Health <= 99 then game.Workspace.Guy:EquipTool(Lighting.LinkedSword) local larm = script.Parent:FindFirstChild("Left Arm") local rarm = script.Parent:FindFirstChild("Right Arm")
function findNearestTorso(pos) local list = game.Workspace:children() local torso = nil local dist = 100 local temp = nil local human = nil local temp2 = nil for x = 1, #list do temp2 = list[x] if (temp2.className == "Model") and (temp2 ~= script.Parent) and (temp2.Name ~= "Noob") then temp = temp2:findFirstChild("Torso") human = temp2:findFirstChild("Humanoid") if (temp ~= nil) and (human ~= nil) and (human.Health > 0) then if (temp.Position - pos).magnitude < dist then torso = temp dist = (temp.Position - pos).magnitude end end end end return torso end
while true do wait(0.1) local target = findNearestTorso(script.Parent.Torso.Position) if target ~= nil then script.Parent.Humanoid:MoveTo(target.Position, target) end end end
|
|
|
| Report Abuse |
|
|
|
| 22 Mar 2015 12:23 AM |
if game.Workspace.Guy.Humanoid.Health <= 99 then game.Workspace.Guy:EquipTool(Lighting.LinkedSword)
local larm = script.Parent:FindFirstChild("Left Arm") local rarm = script.Parent:FindFirstChild("Right Arm")
function findNearestTorso(pos) local list = game.Workspace:children() local torso = nil local dist = 100 local temp = nil local human = nil local temp2 = nil for x = 1, #list do temp2 = list[x] if (temp2.className == "Model") and (temp2 ~= script.Parent) and (temp2.Name ~= "Noob") then temp = temp2:findFirstChild("Torso") human = temp2:findFirstChild("Humanoid") if (temp == nil) and (human == nil) and (human.Health > 0) then if (temp.Position - pos).magnitude < dist then torso = temp dist = (temp.Position - pos).magnitude end end end end return torso end
while true do local target = findNearestTorso(script.Parent.Torso.Position) if target == nil then script.Parent.Humanoid:MoveTo(target.Position, target) end end
end |
|
|
| Report Abuse |
|
|
|
| 22 Mar 2015 12:23 AM |
FIXED*
if game.Workspace.Guy.Humanoid.Health <= 99 then game.Workspace.Guy:EquipTool(Lighting.LinkedSword)
local larm = script.Parent:FindFirstChild("Left Arm") local rarm = script.Parent:FindFirstChild("Right Arm")
function findNearestTorso(pos) local list = game.Workspace:children() local torso = nil local dist = 100 local temp = nil local human = nil local temp2 = nil for x = 1, #list do temp2 = list[x] if (temp2.className == "Model") and (temp2 ~= script.Parent) and (temp2.Name ~= "Noob") then temp = temp2:findFirstChild("Torso") human = temp2:findFirstChild("Humanoid") if (temp == nil) and (human == nil) and (human.Health > 0) then if (temp.Position - pos).magnitude < dist then torso = temp dist = (temp.Position - pos).magnitude end end end end return torso end end
while true do local target = findNearestTorso(script.Parent.Torso.Position) if target == nil then script.Parent.Humanoid:MoveTo(target.Position, target) end end |
|
|
| Report Abuse |
|
|
|
| 22 Mar 2015 12:28 AM |
I think thats correct but its this script thats messing things up. It lets them free roam. Once they get hit how do I stop the script?
h = script.Parent.Humanoid t = script.Parent.Torso while true do local p = Instance.new("Part") p.CanCollide = false p.Transparency = 1 p.Anchored = true p.Position = t.Position + Vector3.new(math.random(-30,30),0,math.random(-30,30)) p.Parent = script.Parent h:MoveTo(Vector3.new(p.Position.X,p.Position.Y,p.Position.Z),p) wait(math.random(2,3)) p:remove() end
|
|
|
| Report Abuse |
|
|
|
| 22 Mar 2015 12:29 AM |
| Nevermind I figured out my problem |
|
|
| Report Abuse |
|
|
Arkose
|
  |
| Joined: 26 May 2013 |
| Total Posts: 745 |
|
|
| 22 Mar 2015 12:30 AM |
Is that all the code @op? Because if it is it will only check the health of the NPC once, which will be before it has taken damage so it will do nothing
|
|
|
| Report Abuse |
|
|