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

How to find just the Z position of a part?

Asked by 5 years ago

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?

0
Sadly you can't change the axis's individually; you have you set them any via `Position = Vector3`. TheeDeathCaster 2368 — 5y
0
smh why u accept his and not mine User#24403 69 — 5y

2 answers

Log in to vote
2
Answered by
Miniller 562 Moderation Voter
5 years ago
Edited 5 years ago

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.
1
Thank you guys for answering so fast! I'll try using that instead! Noonekirby 162 — 5y
1
Thanks for the credit. :) TheeDeathCaster 2368 — 5y
Ad
Log in to vote
1
Answered by 5 years ago

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.

Answer this question