Making gui positions the mouse's position

local frame = script.Parent.Parent.userInterface.badgeFrame
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

frame.InputBegan:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		local badge = Instance.new("TextLabel", script.Parent.Parent.userInterface.badgeFrame)
		badge.Size = UDim2.new(0,50,0,50)
		badge.Text = ""
		badge.BackgroundColor3 = Color3.new(0, 0.666667, 1)
		badge.AnchorPoint = Vector2.new(.5,.5)
		badge.Position = UDim2.new(0.5, mouse.X, 0.5, mouse.Y) - THIS LINE
	end
end)
1 Like

Could you explain more about what the issue is?

Sure, I want the text label’s position to be the mouse’s position. RN it is very far and lower to the right of the mouse.

Im pretty sure all you have to do is remove the 0.5 in the scale columns
UDim2.new(0,mouse.X,0,mouse.Y)

2 Likes

I believe you’d need to remove the 0.5 in the UDim2 but I’m not sure, could you try that?
You also could create a loop and keep setting it until you don’t want to.

1 Like

Yes the mouse’s position is only offset, if you put a GUI at the mouse’s position then apply scale it will mess it up.

As @PapaBreadd said remove the scale in the UDim2

robloxapp-20210513-1507035.wmv (106.9 KB)

Do

local absPos = frameThatYourePuttingItIn.AbsolutePosition
UDim2.new(0,mouse.X-absPos.X,0,mouse.Y-absPos.Y)
1 Like

I just realised, you are trying to use InputBegan on a frame.
InputBegan is a member of UserInputService.
If you wanna click on a gui, you can use GuiButton.MouseButton1Click

Its of both

Kinda confusing on roblox’s part but

My bad. Never seen InputBegan in GuiObject.

That makes it outside of the screen

Can you show your code?
It works for me in my testing

oh wait. the way i put it into my code, it didn’t acocunt for the tween. So i got it after the tween and it works. Thank you

1 Like

I think you should make;

 UDim2.new(0, mouse.X/SizeOfFrame, 0, mouse.Y/SizeOfFrame)