Mouse not aligning to UDim2

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    the label teleports to the mouse constantly
  2. What is the issue? Include screenshots / videos if possible!

    its far out for no good reason it seems
local craftgui = game.Players.LocalPlayer.PlayerGui:WaitForChild("MainGui"):WaitForChild("Crafting")
local options = craftgui:WaitForChild("Options")
local Cop = craftgui:WaitForChild("Coptions")
local label = game.Players.LocalPlayer.PlayerGui.MainGui.Crafting.Labeling
local mouse = game.Players.LocalPlayer:GetMouse()
local currentsection = "M"
function reorganize(replacer)
	-- oopsie this should be on the server
	game.ReplicatedStorage.RemoteEvent:FireServer("Reorganize", replacer, currentsection)
end

local coro = coroutine.create(function()
	while true do wait()
		label.Position = UDim2.new(0,mouse.X, 0, mouse.Y)
	end
end)
coroutine.resume(coro)

craftgui.Tools.MouseButton1Click:Connect(function()
	if currentsection == "T" then
		if options.Visible == false then
			options.Visible = true
		else
			options.Visible = false
		end
	else
		options.Visible = true
		reorganize("T")
		currentsection = "T"
	end
end)


craftgui.Materials.MouseButton1Click:Connect(function()
	if currentsection == "M" then
		if options.Visible == false then
			options.Visible = true
		else
			options.Visible = false
		end
	else
		options.Visible = true
		reorganize("M")
		currentsection = "M"
	end
end)

craftgui.Food.MouseButton1Click:Connect(function()
	if currentsection == "F" then
		if options.Visible == false then
			options.Visible = true
		else
			options.Visible = false
		end
	else
		options.Visible = true
		reorganize("F")
		currentsection = "F"
	end
end)
craftgui.Vehicles.MouseButton1Click:Connect(function()
	if currentsection == "V" then
		if options.Visible == false then
			options.Visible = true
		else
			options.Visible = false
		end
	else
		options.Visible = true
		reorganize("V")
		currentsection = "V"
	end
end)
craftgui.Structures.MouseButton1Click:Connect(function()
	if currentsection == "S" then
		if options.Visible == false then
			options.Visible = true
		else
			options.Visible = false
		end
	else
		options.Visible = true
		reorganize("S")
		currentsection = "S"
	end
end)

options.ChildAdded:Connect(function(child)
	child.MouseButton1Click:Connect(function()
		if child.Parent == options then
			game.Players.LocalPlayer.PlayerGui.MainGui.craftingconfirm.Visible = true
			game.Players.LocalPlayer.PlayerGui.MainGui.craftingconfirm.Resource.Text = child.Text
			game.Players.LocalPlayer.PlayerGui.MainGui.craftingconfirm.Resource:SetAttribute("Name", child.Name)
			game.Players.LocalPlayer.PlayerGui.MainGui.craftingconfirm.Recipe.Text = child:GetAttribute("Recipe")
		end
	end)
	child.MouseButton2Click:Connect(function()
		if child.Parent == options then
			game.ReplicatedStorage.RemoteEvent:FireServer("Craft", child.Name)
		end
	end)
	local MouseOverModule = require(script.MouseOverModule)

	local MouseEnter, MouseLeave = MouseOverModule.MouseEnterLeaveEvent(child)
	MouseEnter:Connect(function()
		if child.Visible == true and child.Parent == options and options.Visible == true then
			label.Visible = true
			label.Text = child:GetAttribute("Recipe")
			MouseLeave:Wait()
			label.Visible = false
		end
	end)
end)

game.Players.LocalPlayer.PlayerGui:WaitForChild("MainGui"):WaitForChild("craftingconfirm"):WaitForChild("yes").MouseButton1Click:Connect(function()
	if game.Players.LocalPlayer.PlayerGui:WaitForChild("MainGui"):WaitForChild("craftingconfirm").Visible == true then
		game.ReplicatedStorage.RemoteEvent:FireServer("Craft", game.Players.LocalPlayer.PlayerGui.MainGui.craftingconfirm.Resource:GetAttribute("Name"))
		game.Players.LocalPlayer.PlayerGui:WaitForChild("MainGui"):WaitForChild("craftingconfirm").Visible = false
	end
end)
game.Players.LocalPlayer.PlayerGui:WaitForChild("MainGui"):WaitForChild("craftingconfirm"):WaitForChild("no").MouseButton1Click:Connect(function()
	if game.Players.LocalPlayer.PlayerGui:WaitForChild("MainGui"):WaitForChild("craftingconfirm").Visible == true then
		game.Players.LocalPlayer.PlayerGui:WaitForChild("MainGui"):WaitForChild("craftingconfirm").Visible = false
	end
end)

for _,child in pairs(game.Players.LocalPlayer.PlayerGui:WaitForChild("MainGui"):WaitForChild("Crafting").Coptions.Materials:GetChildren()) do
	child.Parent = game.Players.LocalPlayer.PlayerGui:WaitForChild("MainGui"):WaitForChild("Crafting").Options
	child.Visible = true
end


What’s the problem? Please explain in full sentences and with references to code.

For some reason when im positioning the label it teleports it all the way over there instead of the mouses position

Is the label parented to the root of the ScreenGui? If not, parent it there.

1 Like

root of the screengui? what do you mean

Just parent the label to the gui and not a frame.

1 Like
local TextLabel = script.Parent
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()

local RunService = game:GetService("RunService")

RunService.RenderStepped:Connect(function()
	TextLabel.Position = UDim2.new(0, Mouse.X, 0, Mouse.Y)
end)

Try this?

Obviously optimize the code to your situation, but this is an example of how you would make the gui follow the player’s mouse