Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

A variable in a Vector3?

Asked by
lucas4114 607 Moderation Voter
9 years ago

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)
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. TheeDeathCaster 2368 — 9y
0
So, how would I put a Position in a Vector3? Something like: AVector3 = Vector3.new (Target.Position) ?????? lucas4114 607 — 9y
0
Yes lucas, that is exactly right BSIncorporated 640 — 9y
0
wait, no BSIncorporated 640 — 9y
View all comments (2 more)
0
anything in the output? BSIncorporated 640 — 9y
0
Nothing... lucas4114 607 — 9y

2 answers

Log in to vote
0
Answered by 9 years ago

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)
Ad
Log in to vote
0
Answered by 9 years ago

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

while wait() do
AVector3 = Target.Position
end
2
You don't even need the Vector3.new() here. Target.Position is already a Vector3 YellowoTide 1992 — 9y
2
Yeah you dont need the Vector3.new() in line 2, it rhymes so its true ;) Hybric 271 — 9y
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... :/ lucas4114 607 — 9y
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) chess123mate 5873 — 9y

Answer this question