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

How to center ScreenGui along with Mouse?

I want to Center the ScreenGui I'm making, I want the Cross Gui Frame to be centered in the mouse. Like the mouse pointing the intersection of the cross.

Meanwhile i want it to center and increase in size simultaneously . While the size increases i want the frame position to be centered. This is what i have.

function Position()
	local SizeX = Crosshair.Size.UDim2.X
	Cross.Position = UDim2.new(0,Mouse.X ,0,Mouse.Y ) -- it has to be something with this
	
end


game:GetService("RunService").RenderStepped:connect(Crosshairs)
for i = 1 ,50, 2 do
	wait()
	Cross.Size = UDim2.new(0,i,0,i)
end

5 comments

0

Ok we have no idea of your hierarchy, your gui appearance, or what went wrong.

0

wait what exactly is the problem here, and we may be needing a bit more of the code depending on it.

0

Here is a Drawing of what i'm trying to accomplish. http://i1174.photobucket.com/albums/r615/RobloxIMG/Demostration_zpswgps9imz.jpg

0

Mouse.X - Crosshair.Size.X/2

0

THat doesn't work

1 answer

✓ Accepted answer

Gui position is based on the top left corner, not the center. To center it you simply add half of its size. Best to use the absolutesize so you don't conflict with scaling.

function Position()
    local size = Cross.AbsoluteSize / 2
    Cross.Position = UDim2.new(0, Mouse.X+size.X, 0, Mouse.Y+size.Y)
end

Mouse.Move:connect(Position) --best event for Position

for i = 1 ,50, 2 do
    wait()
    Cross.Size = UDim2.new(0,i,0,i)
    Position()
end

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