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

How do I get the an X or Y co-ordinate of the position of a part to use in arithemtic operations?

Asked by
ExcelUp 24
6 years ago

I'm wanting to get the specific X/Y co-ordinate of the position of a part to use in an arithmetic operation, and when I attempt to use 'Position.X' or 'Position.Y', it simply says that either of those values cannot be used in arithmetic operations.

0
Both X and Y (and Z) are read only, you'll have to set the position, you can use them for calculating though User#20388 0 — 6y
0
^ What he said. Basically if you want to change the position you will have to add a Vector3(x,y,z) to the set the x, y and z coordinates respectively. TiredMelon 405 — 6y

2 answers

Log in to vote
0
Answered by
Fifkee 2017 Community Moderator Moderation Voter
6 years ago

Alright.

Specific position values (.X, .Y, .Z) are read only. HOWEVER, you can use (.X/400). Don't try to write to read-only values. Bad things happen.

Ad
Log in to vote
0
Answered by 6 years ago

I don't see why not? If you're trying to set part.Position.X = 5 then that won't work.

number Vector3.X [readonly]

local part = workspace.Part

local function NewPos()
    local newPos = Vector3.new(part.Position.X + 5,part.Position.Y + 5,part.Position.Z + 5)
    part.Position = newPos
end

game.Players.PlayerAdded:Connect(function(Player)
    Player.Chatted:Connect(function(msg)
        NewPos()
    end)
end)

Answer this question