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

How do you get the center of the screen with Vector2?

Asked by
Qariter 110
4 years ago

Title explains it, I've tried everything. I know i can do IngoreGuiInSet, but i can't just figure out how to do get the center.

0
use scale, Vector2.new(0.5,0,0.5,0) is the center Leamir 3138 — 4y
0
Tried this before, didn't work. The center was so far up to the left and up. Qariter 110 — 4y
0
Mmm... did you set the AnchorPoint to 0.5, 0.5? Xx_XSanderPlayXx 160 — 4y
0
if u didn't thats why that happens. Xx_XSanderPlayXx 160 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

Set your anchor point to 0.5, 0.5.

https://developer.roblox.com/en-us/api-reference/property/GuiObject/AnchorPoint

0
This isn't for a gui! This is NOT what i meant! Qariter 110 — 4y
Ad
Log in to vote
0
Answered by
SirGamezy 186
4 years ago

If you're using ScreenGuis, use UDim2.

Assuming that a LocalScript is inside your GUI:

local centerScreen = UDim2.new(0, 0, 0, 0)
local gui = script.Parent

gui.Position = centerScreen

If you don't know what UDim2 is, here are the roles of the numbers in it:

UDim2.new(x scale, x offset, y scale, y offset)

I suggest editing the scales, because the offset's size doesn't change according to the device's size.

0
Once again, not for a gui! I'm using it to shoot a raycast towards the center of the player's screen. Qariter 110 — 4y

Answer this question