How to make a script where one UI is always above another? (On Y axis)

I want to make this UI…

Always above this backpack module UI. No matter the screen size or aspect ratio.

I tried making a script repositioning the captures UI above the backpack UI and it never seemed to work no matter what I did with scale, offset etc.

I don’t think there’s a problem with the backpack module itself, it looks like guy was smart and always parented after setting properties. I did waitforchild etc

I’d be extremely grateful if someone wrote this script so I can lazily plug in and play. But seriously, I’d like to learn from it because I don’t understand right now.

However, I don’t really want something more complex than one script that I can copy and paste and put all my GUIs in. This leads me to a more philosophical question…

Is it actually possible to have a nice UI for all players?


Oh, what a lovely UI, with anchor point .5,.5, converted to scale, and with a UIAspectRatioConstraint. All the standard tips people give for a consistent sized UI. Now let’s see what was done in Roblox Studio to create this…


AHHH! CURSES! Get that away from me this instant!

Or am I just uninformed and this isn’t actually philosophical at all?

zindex for guiobjects
DisplayOrder for screenguis

4 Likes

You don’t need a script to do this, try with the Zindex property.

https://devforum.roblox.com/t/what-is-zindex-behaviour/1200087

2 Likes

Ty. I mean above like on the Y axis

2 Likes

Are you looking for A UI like this?

1028

Phone

Or, something like this;

Phone

Laptop

Try setting anchor point to (0.5, 1) and setting position at x(0.5, 0) y(1, -H), H being the height of the backpack.
No scripts needed.

You could also parent them to the same frame and position the frame with anchor point (0.5, 1) and position x(0.5, 0) y(1, 0), this is what i did to keep my hotbar config above my hotbar.


image

1 Like

The backpack is a module. I don’t want to go into the module and mess with that. So it will require a script.

You mean the Y position?
image
How should I convert this to pure offset first? (Parent is frame)

Oooh, so the backpack is created via script too ? Anyway, do u have control over what’s gonna be the backpack’s parent ?
If so I believe my second suggestion is the more consistent one.

Sorry for not catching that on ur post ! It should work if you change the anchor points from (0.5, 0.5) to (0.5, 1) tho.

1 Like

Well that would just be a matter of keeping track of who is the highest and add to the DisplayOrder.

--LocalScript in StarterPlayerScripts
local Players = game:GetService("Players")
local PlayerGui = Players.LocalPlayer:WaitForChild("PlayerGui")

local function updateDisplayOrder()
    local maxY = 0
    local topUI
    for _, gui in ipairs(PlayerGui:GetChildren()) do
        if gui:IsA("GuiObject") then
            local y = gui.AbsolutePosition.Y + gui.AbsoluteSize.Y
            if y > maxY then
                maxY = y
                topUI = gui
            end
        end
    end
    if topUI then
        for _, gui in ipairs(PlayerGui:GetChildren()) do
            if gui:IsA("GuiObject") and gui ~= topUI then
                gui.DisplayOrder = 0
            end
        end
        topUI.DisplayOrder = 1
    end
end

updateDisplayOrder()
PlayerGui.ChildAdded:Connect(updateDisplayOrder)
PlayerGui.ChildRemoved:Connect(updateDisplayOrder)

This may help.. Didn’t test it however.

As far as your GUI looking good on all screens, that is shockingly easier than it seems. In the position you have {0, 0}, {0, 0} .. the first number is the key. That is scale, while the second is offset. If you line it up using scale, it will stay in the same relative position on any screen.

{xScale, xOffset, {yScale, yOffset}