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

How do I change the y position of every part?

I'm (sort of) laying tile in this game. Somehow some of the tiles seem (very randomly) to be .2 above the others on the y axis making them not line up properly. I need to change the y potision of every tile to 0.5.

I want to do this AND keep the changes.

Here is the function I made.

function fix() local children = game.Workspace:GetChildren() children.Position = Vector3.new(Position.x,.5,Position.z) end

fix()

I'm not sure how to change all childrens y position without changing the x and z position.

3 comments

0

are they in a model? named the same? same size? really all i'm asking is if there's a way to reference them all

0

They can all be referenced by workspace:getchildren()

0

I just don't know how to change the y position alone without changing the x and z position. (Look at the edit I made).

1 answer

✓ Accepted answer

Oh well if they can be referenced by that then...

for _, part in pairs(workspace:GetChildren()) do
	part.Position = part.Position + Vector3.new(0, 0.5, 0)
end

edit:

for _, part in pairs(workspace:GetChildren()) do
	if part:IsA("BasePart") then
		part.CFrame = part.CFrame + Vector3.new(0, -part.Position.Y + 0.5, 0)
	end
end

9 comments

0

Running that script alone doesn't do it for me. Sorry I'm really bad at scripting and am just probably forgetting something simple. I need all parts in game.Workspace to have a y position of 0.5, but their x and z positions unchanged.

0

oh well this moves them up by 0.5 but I will change it

0

Am I supposed to just copy the code and run it? Still none of the parts are changed.

0

I would do it in the run bar on the bottom

0

Okay. When I ran it in the output I got a very strange result. Lots of parts were pushed in weird ways while many still remained unchanged.

0

Are you sure the only parts you intended to move were in workspace? I'm not really sure what else to say

0

I moved everything else intro the server storage to get it out of the way. I am running the script you gave me in the output. Some parts stay the exact same and some jump way out of place (like a full stud)

0

ah okay my bad I realize now I should have used CFrame so ill update it again

0

Well that fixed it. Thank you very much for the help.

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