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

How to Make a GUI In the Same Position Despite Screen Size?

I am trying to make an inventory GUI that should always be located just left of the far left edge of the player's screen (regardless of their screen size of course). The idea is that only an image button (part of the inventory frame) is sticking out from the left edge and when you click it, the whole thing moves right onto the screen. In testing mode this works fine, but in play mode (when my screen is full), the inventory GUI is nowhere to be seen. I guarantee this has to do with scaling, but I am unsure of how to fix it other than guessing and checking. Here's some of my code...

local TweenService = game:GetService("TweenService")
local inventory = script.Parent.Parent

function onClicked(GUI)
	local openGoal = {}
	openGoal.Position = UDim2.new(0.02, 0, .5, 0)
	local closeGoal = {}
	closeGoal.Position = UDim2.new(-0.17, 0, .5, 0)
	
	local tweenInfo = TweenInfo.new(2)
	local openInventory = TweenService:Create(inventory, tweenInfo, openGoal)
	local closeInventory = TweenService:Create(inventory, tweenInfo, closeGoal)
	
	local curr_pos = inventory.Position
	if curr_pos.X.Scale <= -.169 then
		openInventory:Play()
	else if curr_pos.X.Scale >= 0.019 then
		closeInventory:Play()
	end
	end
end
script.Parent.MouseButton1Click:connect(onClicked)

1 answer

You can use the property AnchorPoint. Basically what AnchorPoint is, it's literally a point, and it needs 2 parameters, the X and Y values. The values need to be between 0-1 (0.1, 0.2, 0.5 etc). If you have both X and Y values 0.5, the point will be in the middle, and that means that it will be in the same position no matter what your screen size is. You will also have to find another position that's perfect for you. Hope I helped! (normally x and y values should be 0.5 so they show the same on each player's interface)

2 comments

0

So should I not use the Position property at all? Merely tween the anchor point?

0

the anchor point is just so it's on the exact position for every single device. you have to use position.

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