Neo1035
|
  |
| Joined: 25 Jun 2008 |
| Total Posts: 13076 |
|
|
| 31 Jan 2013 07:11 PM |
repeat wait() until game.Players.LocalPlayer.Character ~= nil
grass = Instance.new("Part", game.Workspace.CurrentCamera) grass.Anchored = true player = game.Players.LocalPlayer.Character.Head
if (player.Position - grass.Position).magnitude < 10 then grass.Position = player.Position + Vector3.new(math.random(-10, 10), -4, math.random(-10, 10)) end
It's supposed to check if the player's position is further than 10 studs away from the brick, then re-position the brick at a random position 10 studs away.
I see the brick sitting at 0,0,0 but it does nothing and there is no error message. Any idea what the problem could be? |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 31 Jan 2013 07:34 PM |
LocalPlayer? Is it a local script, if so, is it in backpack/gui? |
|
|
| Report Abuse |
|
|
Neo1035
|
  |
| Joined: 25 Jun 2008 |
| Total Posts: 13076 |
|
| |
|
|
| 31 Jan 2013 08:28 PM |
Try adding a loop, so it checks all the time instead of just once:
while wait(.1) do -- the same as while true do, but with a wait if (player.Position - grass.Position).magnitude < 10 then grass.Position = player.Position + Vector3.new(math.random(-10, 10), -4, math.random(-10, 10)) end end
Wiki Profile: http://wiki.roblox.com/index.php/User:Nelson |
|
|
| Report Abuse |
|
|
|
| 31 Jan 2013 08:33 PM |
| Your checking for if it is closer then 10. Swap the "<" to a ">" |
|
|
| Report Abuse |
|
|
|
| 31 Jan 2013 08:34 PM |
| By the way, you are positioning it farther away then 10 if it is farther then 10. Your gona have it jumping all over the place if you loop it. |
|
|
| Report Abuse |
|
|
|
| 31 Jan 2013 08:39 PM |
Insert this for the new position of the part. It will always be slightly shorter then 10 in magnitude. Just insert "part.Position = randomVector()" along with the function.
function randomVector() x = math.random(-10, 10) - 0.1 y = 4 z = (x^2 + 16)^(0.5) - return Vector3.new(x-0.2,y,z-0.2) end |
|
|
| Report Abuse |
|
|
Neo1035
|
  |
| Joined: 25 Jun 2008 |
| Total Posts: 13076 |
|
|
| 31 Jan 2013 08:39 PM |
That works, however I want to make it so that if you leave the magnitude distance it re-adjusts itself into a position near you again, and it only does this when you pass the magnitude distance.
I'll expand on it, but it's supposed to be the foundation of a script that makes it look like there's grass around you that appears in front of you and disappears behind you. |
|
|
| Report Abuse |
|
|
Neo1035
|
  |
| Joined: 25 Jun 2008 |
| Total Posts: 13076 |
|
|
| 31 Jan 2013 08:41 PM |
| Oh, well Arbiter just solved that problem. Thank you both a ton for the help! It's always the obvious things.. |
|
|
| Report Abuse |
|
|