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 » Scripting Helpers
Home Search
 

Re: Weird error

Previous Thread :: Next Thread 
RealistK is not online. RealistK
Joined: 20 Feb 2011
Total Posts: 3489
20 Jul 2014 01:36 PM
So when you get near a monster and then you run out of their maxdistance, they are supposed to walk back, but what they do is:
You suddenly control them, if you press up they go down, if you press left they go right.
Weird..
how do I fix it that they just walk back to their original position?
Value with distance and a value with maxdistance in the script.


local larm = script.Parent:FindFirstChild("Left Arm")
local rarm = script.Parent:FindFirstChild("Right Arm")
maxdist = script.MaxDistance.Value
start = script.Parent.Torso.Position

function findNearestTorso(pos)
local list = game.Workspace:children()
local torso = nil
local dist = script.Distance.Value
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("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)
newdist = script.Parent.Torso.Position
dist = newdist - start
print(dist)
if dist.x < maxdist and dist.x > -maxdist and dist.z < maxdist and dist.z > -maxdist then
if target ~= nil then
script.Parent["Enemy"]:MoveTo(target.Position, target)
end
else
script.Parent["Enemy"]:MoveTo(start)
end
end
Report Abuse
PalmToFace is not online. PalmToFace
Joined: 25 Oct 2010
Total Posts: 65
20 Jul 2014 01:40 PM
Humanoid:MoveTo()
Report Abuse
RealistK is not online. RealistK
Joined: 20 Feb 2011
Total Posts: 3489
20 Jul 2014 01:42 PM
It's a RPG enemy he, the name is Enemy of the humanoid.
Report Abuse
RealistK is not online. RealistK
Joined: 20 Feb 2011
Total Posts: 3489
20 Jul 2014 02:39 PM
meep
Report Abuse
RealistK is not online. RealistK
Joined: 20 Feb 2011
Total Posts: 3489
20 Jul 2014 04:06 PM
bump
Report Abuse
RealistK is not online. RealistK
Joined: 20 Feb 2011
Total Posts: 3489
20 Jul 2014 05:55 PM
bump
Report Abuse
bibo5o is not online. bibo5o
Joined: 17 Jan 2009
Total Posts: 414
20 Jul 2014 05:58 PM
Sorry real, I don't think people are ignoring this, they probably just don't understand what's going on.
Report Abuse
Notunknown99 is not online. Notunknown99
Joined: 05 Sep 2008
Total Posts: 25360
20 Jul 2014 06:22 PM
if dist.x < maxdist and dist.x > -maxdist and dist.z < maxdist and dist.z > -maxdist then

if (dist.x*dist.x + dist.z*dist.z) < maxdist*maxdist then --a^2 + b^2 == c^2, like magnitude but fasterer.
Report Abuse
SilverArgentum is not online. SilverArgentum
Joined: 01 Nov 2011
Total Posts: 1162
20 Jul 2014 06:24 PM
I think people just don't want to read bulk scripts.
Report Abuse
Notunknown99 is not online. Notunknown99
Joined: 05 Sep 2008
Total Posts: 25360
20 Jul 2014 06:29 PM
script.Parent["Enemy"]:MoveTo(target.Position, target)

Try removing the ", target".
Report Abuse
RealistK is not online. RealistK
Joined: 20 Feb 2011
Total Posts: 3489
21 Jul 2014 04:05 AM
Removing target didn't work. :s
The weirdest part is that it works fine in play solo, but it doesn't work in the actual server.
Report Abuse
SilverArgentum is not online. SilverArgentum
Joined: 01 Nov 2011
Total Posts: 1162
21 Jul 2014 11:27 AM
That probably means that the script runs right at the creation of the server.
Report Abuse
RealistK is not online. RealistK
Joined: 20 Feb 2011
Total Posts: 3489
21 Jul 2014 01:59 PM
hmm, how to fix?
Report Abuse
CWRA0444 is not online. CWRA0444
Joined: 14 Jan 2010
Total Posts: 6013
21 Jul 2014 02:02 PM
add a wait(2) before everything
Report Abuse
RealistK is not online. RealistK
Joined: 20 Feb 2011
Total Posts: 3489
21 Jul 2014 05:03 PM
everything..?
Report Abuse
brinkokevin is not online. brinkokevin
Joined: 25 Jul 2012
Total Posts: 1673
21 Jul 2014 05:09 PM
lol i remember when i was creating rpg i had same error brb
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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