So then how would I adjust/correct for the discrepancy?
Download: SelectionBoxOnly.rbxl (58.1 KB)
Script:
startPos = Vector2.new(Mouse.X, Mouse.Y)
selectionBox.Position = UDim2.fromOffset(startPos.X, startPos.Y)
Thanks!
So then how would I adjust/correct for the discrepancy?
Download: SelectionBoxOnly.rbxl (58.1 KB)
Script:
startPos = Vector2.new(Mouse.X, Mouse.Y)
selectionBox.Position = UDim2.fromOffset(startPos.X, startPos.Y)
Thanks!
you can subtract the startpos by game:GetService("GuiService"):GetGuiInset()
Give @gamemaster4268 the solution as I didn’t even know that was a thing, but basically what he’s saying is to offset your current mouseY position (in pixels) with the height of the GUI inset (also in pixels):
local currentPos = Vector2.new(Mouse.X, Mouse.Y + game:GetService("GuiService"):GetGuiInset().Y)
Yep. How’d you know it was .Y
after GetGuiInset()
? It doesn’t give me a suggestion of what available properties GetGuiInset has, and the documentation is of no help either…
Wait a minute, actually, I need to look into this more before writing my reply-
It worked lol, don’t worry
That’s why I was so surprised
Okay I got it – I know how to explain it.
Actually, I didn’t notice that it returned a tuple and NOT a standalone Vector2 (I got lucky lol). Let me visualize what’s going in:
It returns two Vector2 values in a tuple, which means you would usually list them like:
local topLeftCorner, bottomRightCorner = game:GetService("GuiService"):GetGuiInset()
warn(topLeftCorner) -- 0, 58 (for me)
warn(bottomRightCorner) -- 0, 0
Just doing game:GetService("GuiService"):GetGuiInset()
returns the first Vector2 in the tuple which is on the top left – whiich just so happens to be the right Vector2. Hence, I’m really just doing Mouse.Y + Vector2.Y