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

posY and posZ of a part variable?

I got this script:

local part = Instance.new("Part")

function spawnPart(posX)
	part.Position = Vector3.new(posX,posY,PosZ)
end

while true do
	spawnPart()
end

Instead of posY and PosZ, I want the current position of the variable part. How can I do it?

2 answers

If you would like to keep the original position Y and Z position of your part, you have to references it by doing this

part.Position.Y --Y position
part.Position.Z --Z position

Also, based on your script, it looks like you would want a part to keep respawning over and over again, there seems to be a minor mistake.

In order to create a part over and over again, you must put the part variable inside the function so it is called multiple times.

Second, I would recommend putting a wait() on your while loop because if you won't, it is going to crash.

function spawnPart(posX)
    local part = Instance.new("Part")
    part.Position = Vector3.new(posX,part.Position.Y, part.Position.Z )
    part.Parent = workspace --You should also parent your part somewhere so it spawns.
end

while true do
    spawnPart(10) --The 10 can be any number based on whatever X position of the part you want.
    wait() --Add a wait to prevent crashing
end

In your script, it seems like you only want the part's X axis to be customizable with a parameter, so you should enter a value for it, it can be any number value.

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