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: If Then Statement not functional

Previous Thread :: Next Thread 
Neo1035 is not online. 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 is not online. 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 is not online. Neo1035
Joined: 25 Jun 2008
Total Posts: 13076
31 Jan 2013 07:42 PM
Local script, backpack
Report Abuse
MeBilly8440 is not online. MeBilly8440
Joined: 27 Jul 2009
Total Posts: 2783
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
ArbiterOfDeath is not online. ArbiterOfDeath
Joined: 20 Jun 2011
Total Posts: 1458
31 Jan 2013 08:33 PM
Your checking for if it is closer then 10. Swap the "<" to a ">"
Report Abuse
ArbiterOfDeath is not online. ArbiterOfDeath
Joined: 20 Jun 2011
Total Posts: 1458
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
ArbiterOfDeath is not online. ArbiterOfDeath
Joined: 20 Jun 2011
Total Posts: 1458
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 is not online. 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 is not online. 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
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