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

How do I Change a Text Label's Y Position?

for p = .1,.15,.01 do

script.Parent.Parent.PlayerGui.bag_collected.bg.Position.Y = Vector2.new(p,0)

wait()

end

and it says Y cant be assigned to, i dont know how to fix this, its probably simple, but i cant figure it out, please help. Thanks :)

3 comments

0

GUI's require U-Dimensional Size/Position assignments. Use UDim2.new() instead.

0

label.Position = label.Position + UDim2.new(0,0,0, 50)

Change 50 to the number you would like it to move by.

0

You should also be using TweenPosition as it'll create a smooth transition between your current and desired Position, with multiple styles too.

1 answer

You cannot assign the Y on its own, you gotta add to a new Udim2 value to the label's position, and that value will have X set to 0 so it doesn't effect the X axis for the label, but you can add more to the Y axis and that's by either adding scale or offset. And this is just a quick and this is jsut a little explanation. Udim2.new = (x, x1, y, y2)

| x | is the X scale | | x1 | is the X offset| | y | is the Y scale | | y1 | is the Y offset |

And of course if you wanna go deeper just search more!

Now instead of just changing the Y, do this:

local label = script.Parent.Parent.PlayerGui.bag_collected.bg
--I also assigned a variable that refers to your label just to make stuff easier.

for p = .1,.15,.01 do

    label.Position = Udim2.new(0,0,0,p)
  
    wait()
    
end

and that's it. Another thing is you can make this way cooler and smoother, as Fearhen said you can use :TweenPosition. You can check the different styles and paramaters that you can use with this function here. I would just be showing how to change the position.

local label = script.Parent.Parent.PlayerGui.bag_collected.bg

label:TweenPosition(Udim2.new(0,0,0,.15)
--as you can see were using a udim2 value here too. this is just an example, play with the numbers however you want to!

An example.

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