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 of a parts position?

whenever I do script.Parent.Position = Vector3.new(y)-1 or anything like that it errors out saying Y cannot be assigned what am I doing wrong here because when I do script.Parent.Position. I get the ability to pick X, Y, Z but I want to pick y then subtract .5 from it so when it touches the ground the y Value is -.5 of where it would be

heres my script so far

script.Parent.Touched:connect(function(hit)
	local p = Instance.new("Part", workspace)
	p.Anchored = true
	p.Position = script.Parent.Position
	p.Size = Vector3.new(0.3, 0.3, 0.3)
	p.Color = Color3.new(0, 0, 0)
	p.Position.y = Vector3.new(p.Position.y -1)
	script.Parent:Destroy()
end)

3 answers

✓ Accepted answer

You cannot directly edit the members of a multi-member data type such as Vector3 or UDim2, you have to edit it all at once.

Something to keep in mind, though, is that the current value of the property is kept until the line setting the new value is fully interpreted:

p.Position= Vector3.new(p.Position.X, p.Position.Y - 1, p.Position.Z)

--or, alternatively:

p.Position = p.Position - Vector3.new(0, 1) --any trailing zeroes are automatically filled in for you.

3 comments

3

sadly this doesn't work

1

Are you getting any error? If the box is colliding with a brick you want it to phase through, you'll have to use CFrame. (Replace .Position in the second method with .CFrame on both bits.)

3

oh okay thank you

Your line 7 would be:

p.Position = p.Position - Vector3.new(0,0.5,0)

If it were to be .5. There is a Y property of Vector3, but you can't just set the value the way you're attempting.

Thanks for helping me It was starting to annoy me because I couldn't get it to work xD

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