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: Help needed for a following script

Previous Thread :: Next Thread 
lookathis is not online. lookathis
Joined: 29 Aug 2008
Total Posts: 853
23 Feb 2013 05:05 PM
Hey there
I decided to start learning to script, so I decided to look into different scripts and try and change the values of them etc, and if possible, try and use it in my game.

The problem is that im trying to make a model follow me (And only me) and I have a script for that, however, the model follows me way to close to the torso and instead I wanted it to follow me 2-3 studs behind me. I was thinking of trying to place a "- 2" somewhere in the hope it would be "(temp.Position - pos - 2).magnitude < dist" however, I tried it in multiple places with no luck, so I was wondering if the forums could help me..

---
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 = 20
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)
if target ~= nil then
script.Parent.Humanoid:MoveTo(target.Position, target)
end
end
---

When I do at a "-2" the script usually gives up and doesnt follow me at all.

Thanks!
Report Abuse
lookathis is not online. lookathis
Joined: 29 Aug 2008
Total Posts: 853
24 Feb 2013 04:26 AM
Bump since no ones answered...
Report Abuse
blockold is not online. blockold
Joined: 25 Aug 2008
Total Posts: 1411
24 Feb 2013 04:51 AM
No idea.
Report Abuse
lookathis is not online. lookathis
Joined: 29 Aug 2008
Total Posts: 853
24 Feb 2013 04:55 AM
If you had no idea, then why did you answer the thread? It doesn't really help me in any way.
Report Abuse
blockold is not online. blockold
Joined: 25 Aug 2008
Total Posts: 1411
24 Feb 2013 04:57 AM
Because I didn't want to make you feel worthless, with nobody actually answering this thread.
Report Abuse
Infocus is not online. Infocus
Joined: 28 Apr 2011
Total Posts: 8022
24 Feb 2013 05:01 AM
Never really worked with magnitude just yet, but you can make the script check if the distance between you two is only 3 studs.
Maybe like this:

if plyr.magnitude - whateer

Idk lal
Report Abuse
lookathis is not online. lookathis
Joined: 29 Aug 2008
Total Posts: 853
24 Feb 2013 01:54 PM
Does anyone esle have any ideas on how to fix this?
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