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

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

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.

2 comments

0

Both X and Y (and Z) are read only, you'll have to set the position, you can use them for calculating though

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.

2 answers

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.

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)

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