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 |
|
|
|
| 09 Dec 2014 07:35 PM |
vector3 is a userdata
variable = tostring(script.Parent.BodyPosition.maxForce) |
|
|
| Report Abuse |
|
|
|
| 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
|
  |
| 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 |
|
|
|
| 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 |
|
|
|
| 09 Dec 2014 07:53 PM |
Accomplishable, stop trolling. :(
Use what I said, your code is perfect the way it is. |
|
|
| Report Abuse |
|
|
|
| 09 Dec 2014 07:54 PM |
not trolling
you can't s save userdata to data store |
|
|
| Report Abuse |
|
|
|
| 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
|
  |
| Joined: 10 Dec 2011 |
| Total Posts: 603 |
|
|
| 09 Dec 2014 08:28 PM |
| Sorry about accomp he jst sucks xD |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|