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: Animation won't play for NPC

Previous Thread :: Next Thread 
TwistedMemories is not online. TwistedMemories
Joined: 08 Jul 2013
Total Posts: 565
15 Jul 2015 01:30 AM
Ok, this script is supposed to make the NPC follow a player and it plays the animation at the same time. Although, I notice that the animation doesn't play. There is no error in the output. Could it be possible that its the way the NPC is set up? Here's what I have:

function findNearestTorso(pos)
local list = game.Workspace:children()
local torso = nil
local dist = 1500
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) then
temp = temp2:findFirstChild("Right Arm")
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
local Anim = script.Parent.AnimationController:LoadAnimation(script.Parent.Animation)
Anim:Play()
print("Work")
end
end
end
end
return torso
end

while true do
wait(math.random(1,5))
local target = findNearestTorso(script.Parent.Torso.Position)
if target ~= nil then
script.Parent.Mutant:MoveTo(target.Position, target)
end
end
Report Abuse
TwistedMemories is not online. TwistedMemories
Joined: 08 Jul 2013
Total Posts: 565
15 Jul 2015 01:52 AM
Bump
Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
15 Jul 2015 02:00 AM
Make sure there is a target. Try printing the target

print(target)
print(target.Parent)

if its not printing then its not finding the target.


"Talk is cheap. Show me the code." - Linus Torvalds
Report Abuse
TwistedMemories is not online. TwistedMemories
Joined: 08 Jul 2013
Total Posts: 565
15 Jul 2015 02:04 AM
Cool method, and it said nil. How do I make it so that it won't be a nil value anymore?
Report Abuse
TwistedMemories is not online. TwistedMemories
Joined: 08 Jul 2013
Total Posts: 565
15 Jul 2015 02:48 AM
Bump
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