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

How do i add to the position of a Part?

Asked by 9 years ago
a = script.Parent -- Shows that anywhere in the script showing "a" is about the part.

function OnClicked() -- If an "OnClicked" function is triggered it runs the script.
    print(a.Name) -- Shows the name of the part in the output.
    local b = a:clone() -- Clones part.
    b.Parent = game.Workspace -- Places part in workspace.
    b.Position.X +6 -- Error

end -- Ends the function

a.ClickDetector.MouseClick:connect(OnClicked) -- Triggers an "OnClicked" function when a is Clicked.

2 answers

Log in to vote
0
Answered by 9 years ago

You don't add a number to the position, you need to add a whole other Vector3 value since Position is a vector3 value. Also, use a "=" to set a property. One equal sign means setting a property, Two equal signs are for if statements.


Final Product

a = script.Parent -- Shows that anywhere in the script showing "a" is about the part.

function OnClicked()
    print(a.Name)
    local b = a:clone()
    b.Parent = game.Workspace
    b.Position = b.Position + Vector3.new(6) --Vector3.new(6) is the same as Vector3.new(6,0,0); Just taking shortcuts!

end

a.ClickDetector.MouseClick:connect(OnClicked)

Hope it helps!

0
How do i set a Question as Answered? SamTheDeveloper 85 — 9y
Ad
Log in to vote
0
Answered by
Ryzox 220 Moderation Voter
9 years ago

Position is a Vector3 value so you must use Vector3 when doing it. Although the way you are doing it is by accessing the X axis of the parts position and changing it, so to do that you must do:

b.Position.X = b.Position.X + 6

and for Vector3 it would be

b.Position = b.Position + Vector3.new(6,0,0)

Answer this question