Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

A variable in a Vector3?

Yea so, the title says it all... But heres just an example...

Target = game.Workspace.Target

AVector3 = Vector3.new (0,0,0) -- How would I make this vector3 the same as Target.Position...?(Because, Target.Position is moving, so it changes)

6 comments

0

A 'BasePart''s Position is already a 'Vector3' Value, however, I primarily use 'CFrame''s to accomplish a lot of Part Positioning, but, that is harder to do.

0

So, how would I put a Position in a Vector3? Something like: AVector3 = Vector3.new (Target.Position) ??????

0

Yes lucas, that is exactly right

0

wait, no

0

anything in the output?

0

Nothing...

2 answers

✓ Accepted answer

Instead of using a variable, consider using a function:

AVector3 = function() return game.Workspace.Target.Position end
--when you need to use it:
value = AVector3()

Or you can use a .Changed event to automatically update AVector3:

workspace.Target.Changed:connect(function(prop)
	AVector3 = workspace.Target.Position
end)

You need to add a loop so that it finds the Target constantly:

while wait() do
AVector3 = Target.Position
end

4 comments

2

You don't even need the Vector3.new() here. Target.Position is already a Vector3

2

Yeah you dont need the Vector3.new() in line 2, it rhymes so its true ;)

0

Uh, well... I needed to have the thing in a function, puting a while wait() do would never finish what the rest of the script was ment to do... :/

1

You'd need to put the while loop in a coroutine. However, using a while loop for this job is less efficient (if Target doesn't move/change much) and less accurate (while Target moves, this loop might run, then the physics engine could update Target again, and if another coroutine checks AVector3, it will get the old value)

This discussion is preserved as it was. New answers, comments, and votes are closed.