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

How to find just the Z position of a part?

I want to make a sliding part that can work anywhere, but I can't seem to change the Z position without moving the X and Y. I've tried this code

while true do
script.Parent.Position.Z = Vector3.new(5)
print(script.Parent.Position.Z)
			wait(0.1)
			end

Help?

2 comments

0

Sadly you can't change the axis's individually; you have you set them any via Position = Vector3.

0

smh why u accept his and not mine

2 answers

✓ Accepted answer

as TheeDeathCaster said, you can't just change the Z coordinate, you need to change the whole position, e.g

script.Parent.Position = Vector3.new(script.Parent.Position.X, script.Parent.Position.Y, 5) -- This will just change the Z coordinate.

2 comments

1

Thank you guys for answering so fast! I'll try using that instead!

1

Thanks for the credit. :)

You cannot assign the individual properties of a Vector3. But what you can do is add/subtract/multiply/divide a Vector3 to another Vector3:

while true do
    script.Parent.Position = script.Parent.Position + Vector3.new(0, 0, 5)
    wait(0.1)
end

This here is just adding 5 to the Z axis. And 0 to the other axes so the Z axis is the only one changing.

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