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

How do I change the y of a parts position?

Asked by
Prioxis 673 Moderation Voter
9 years ago

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

Log in to vote
4
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
9 years ago

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
sadly this doesn't work Prioxis 673 — 9y
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.) adark 5487 — 9y
3
oh okay thank you Prioxis 673 — 9y
Ad
Log in to vote
2
Answered by
Shawnyg 4330 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
9 years ago

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.

Log in to vote
1
Answered by
Prioxis 673 Moderation Voter
9 years ago

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

Answer this question