For context, I have a 2 separate UIs, one that displays a player’s units, and another that slides out from underneath when hovering over a unit to display its information.
The tweening works on most aspect ratios, but when it comes to overly long resolutions, the tween shoots all the way out to the right. I am using a scale factor of adding its primary position (centered in the middle of the screen) to a UDim2.new(0.38, 0, 0, 0). AnchorPoints are set to 0.5, and everything has a ratio constraint and their sizes and positions by scale. It might be a bit of a nitpick, but I want to make sure everything looks fluid.
I genuinely couldn’t find a specific post that addresses my specific problem, and if anyone could help, that would be greatly appreciated! I’m still learning how to do all of this GUI stuff. Thanks!
local TS = game:GetService("TweenService")
local remoteVariables = require(game.ReplicatedStorage.Modules:WaitForChild("RemoteVariables"))
local player = game.Players.LocalPlayer
local inventoryFrame = script.Parent.Frames:WaitForChild("InventoryFrame")
-- ------------------------------
-- Unit Display Information
-- ------------------------------
local unitInformationDisplayFrame = script.Parent.Frames:WaitForChild("UnitDisplayInformationFrame")
local timer = 0.2
local uiButtonTweenInfo = TweenInfo.new(timer, Enum.EasingStyle.Circular)
local startTS = TS:Create(unitInformationDisplayFrame, uiButtonTweenInfo, {Position = inventoryFrame.Position + UDim2.new(0.38, 0, 0, 0)})
local leaveTS =TS:Create(unitInformationDisplayFrame, uiButtonTweenInfo, {Position = inventoryFrame.Position})
local function BindButtonToFunction(btn)
btn.MouseEnter:Connect(displayUnitInformation)
btn.MouseLeave:Connect(removeUnitInformation)
end
connectionEvent.Event:Connect(function()
for _, v in pairs(player.PlayerGui.CoreGUI.Frames.InventoryFrame.InventoryScroll:GetChildren()) do
if v:IsA("ViewportFrame") or v:IsA("Frame") then
BindButtonToFunction(v:FindFirstChild("FrameInteractable"))
end
end
end)
function displayUnitInformation()
if not leaveTS.Completed then leaveTS.Completed:Wait() end
if not remoteVariables.GetTweenPlayingState() then startTS:Play() end
end
function removeUnitInformation()
if not startTS.Completed then startTS:Cancel() end
leaveTS:Play()
end
Well, for simplicity, I suggest you find two Scaled positions for the sidebar: one for when showing, and one more for hiding it. Then you can use those two positions to Tween the sidebar.
local showPosition = -- Your scaled UI position here
local hidePosition = -- Your scaled UI position here
-- Make tween from showPos to hidePos
-- Make tween from hidePos to showPos
-- jaiohjeiwqehqw...