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: Storing Vector3 values in a variable

Previous Thread :: Next Thread 
mudkip99 is not online. mudkip99
Joined: 17 Jun 2008
Total Posts: 3362
09 Dec 2014 07:33 PM
Simple question, hopefully simple answer.

I need to store a Vector3 value of an object in a variable, is it possible? Here's an example: I want to save the maxForce values of BodyPosition in a variable, I'd assume it would be something like

variable = script.Parent.BodyPosition.maxForce

but I just get an error if I try to do that. This is something I'd assume would be simple, but I can't quite figure it out.
Report Abuse
Accomplishable is not online. Accomplishable
Joined: 13 Aug 2009
Total Posts: 6207
09 Dec 2014 07:35 PM
vector3 is a userdata


variable = tostring(script.Parent.BodyPosition.maxForce)
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
09 Dec 2014 07:35 PM
That works. The error must not be because of that. Try using WaitForChild, in case BodyPosition is still loading when that line is executed.
Report Abuse
mudkip99 is not online. mudkip99
Joined: 17 Jun 2008
Total Posts: 3362
09 Dec 2014 07:47 PM
tostring works fine if I'm trying to print it, but in my situation I need to store the value of the Vector3 to set the maxForce back to the value stored in the variable later, where a string isn't particularly useful.
I could be approaching this the wrong way, I am pretty novice at scripting.
Report Abuse
Accomplishable is not online. Accomplishable
Joined: 13 Aug 2009
Total Posts: 6207
09 Dec 2014 07:52 PM
variable = tostring(script.Parent.BodyPosition.maxForce);

local nums = {};

local count = 0;

for get in string.gmatch(variable, "%d+") do
count = count + 1;
nums[count] = tonumber(get);
end

script.Parent.BodyPosition.maxForce = Vector3.new(nums[1], nums[2], nums[3]);
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
09 Dec 2014 07:53 PM
Accomplishable, stop trolling. :(

Use what I said, your code is perfect the way it is.
Report Abuse
Accomplishable is not online. Accomplishable
Joined: 13 Aug 2009
Total Posts: 6207
09 Dec 2014 07:54 PM
not trolling

you can't s save userdata to data store
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
09 Dec 2014 08:06 PM
He said nothing about DataStore. He said assign it to a variable. Not assign it to a key in DataStores.

His code was correct, he probably needed WaitForChild.
Report Abuse
lsp425 is not online. lsp425
Joined: 10 Dec 2011
Total Posts: 603
09 Dec 2014 08:28 PM
Sorry about accomp he jst sucks xD
Report Abuse
Accomplishable is not online. Accomplishable
Joined: 13 Aug 2009
Total Posts: 6207
09 Dec 2014 09:59 PM
^ is mad my game is better than his


I teach him new things about scripting on a daily basis
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