generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Simple Scripting Help

Previous Thread :: Next Thread 
cooldrewbie is not online. cooldrewbie
Joined: 26 Jun 2010
Total Posts: 2498
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
BothAngles is not online. BothAngles
Joined: 01 Dec 2011
Total Posts: 9604
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
BothAngles is not online. BothAngles
Joined: 01 Dec 2011
Total Posts: 9604
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
cooldrewbie is not online. cooldrewbie
Joined: 26 Jun 2010
Total Posts: 2498
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
cooldrewbie is not online. cooldrewbie
Joined: 26 Jun 2010
Total Posts: 2498
22 Mar 2015 12:29 AM
Nevermind I figured out my problem
Report Abuse
Arkose is not online. 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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image