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

Trying to reposition GUI with script is putting it in the top corner?

Asked by 5 years ago

I'm trying to give the GUI frame a position but this script always puts it back into the top left corner of the screen, no matter what numbers I put into it. Why is it doing that?

game.Players.LocalPlayer.PlayerGui.ManaGUI.ManaFrame.Position = UDim2.new{0, 331},{0, 226}

2 answers

Log in to vote
0
Answered by
Vid_eo 126
5 years ago

You could use TweenPosition to Reposition it and make it slide across the screen:

game.Players.LocalPlayer.PlayerGui.ManaGui.ManaFrame:TweenPosition(UDim2.new(0, 331, 0, 226), 'Out', 'Quad', 1) --The 1 represents the amount of time it takes to tween

If you don't want to tween it, I think your problem could be that you're using pixels. You shouldn't use pixels to position GUIs because then the position will be different for different devices. Set the AnchorPoint of the GUI to 0.5, 0.5 and use the position relative to the screen size (i.e. (0.5, 0, 0.5, 0) positions it in the center of the screen.

This could also fix your issue (I think):

game.Players.LocalPlayer.PlayerGui.ManaGui.ManaFrame.Position = UDim2.new(0, 331, 0, 226)
Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

UDim2.new{0, 331},{0, 226}

means nothing to roblox lua, so it errors.

There is a function named new in the table UDim2 though. It takes 4 arguments which are numbers.

Calling a function:

function(arg1,arg2...)

Calling the function UDim2.new with 4 arguments.

UDim2.new(0, 331, 0, 226)

Full Correct Code:

game.Players.LocalPlayer.PlayerGui.ManaGUI.ManaFrame.Position = UDim2.new(0, 331, 0, 226)

Answer this question