How do I create 'tooltip' TextLabel in Plugin

When I do this:

local HoverBox = Instance.new("TextLabel")
HoverBox.Parent = Widget
HoverBox.Size = UDim2.new(0.25, 0, 0.25, 0)
HoverBox.Position = UDim2.new(0.25, 0, 0.25, 0)
HoverBox.Text = "Test"
HoverBox.Visible = true
HoverBox.ZIndex = 2

plugin:GetMouse().Move:Connect(function()
	HoverBox.Position = UDim2.new(0, plugin:GetMouse().X , 0, plugin:GetMouse().Y )
end)

TextLabel is off like half of the screen, why does this happen, and how can I fix that?

1 Like

By default, Guis are positioned at their top-left corner. You can try changing its AnchorPoint to 0.5, 0.5, so that it’s positioned at the middle, or adjust its position like so:

local a = HoverBox.AbsoluteSize
HoverBox.Position = UDim2.new(0, plugin:GetMouse().X + a.X/2, 0, plugin:GetMouse().Y + a.Y/2)

What do you mean by off half of the screen, could you provide an image showcasing the issue?

This still did not fixed my issue, my TextLabel still is off the mouse position.

Try wrapping the:

HoverBox.Position = UDim2.new(0, plugin:GetMouse().X , 0, plugin:GetMouse().Y )

in a while loop for testing and test and see if that does anything differently

Try this:

local absSize = workspace.CurrentCamera.ViewportSize
local pos = Vector2.new(plugin:GetMouse().X, plugin:GetMouse().Y)
HoverBox.Position = UDim2.new(pos.X / absSize.X, 0, pos.Y / absSize.Y, 0)

Same thing, nothing different. I am sure.

Bit different, but still did not solved issue.

I have a ui like this that works, the mouse is in the center of the frame 100 percent of the time

RS = game:GetService("RunService")
local Mouse = game.Players.LocalPlayer:GetMouse()
RS.RenderStepped:Connect(function()
	Frame.Position = UDim2.new(here you put the scale factor you used divided by 2, Mouse.X, here you put the scale factor you used divided by 2, Mouse.Y)
end)

This worked for me. Perhaps you are setting it up wrong?

image

Here is the code I'm using.
-- [[ Service Declarations ]] --

local runService = game:GetService("RunService")
local coreGUI = game:GetService("CoreGui")

-- [[ Variable Declarations ]] --

--// Camera

local camera = workspace.CurrentCamera

--// UI

local container = Instance.new("ScreenGui")
local toolTipLabel = Instance.new("TextLabel")

-- [[ Function Declarations ]] --

local function updateToolTip()
	local mousePosition = plugin:GetMouse()
	local x, y = mousePosition.X, mousePosition.Y
	
	toolTipLabel.Position = UDim2.new(0, x, 0, y)
end

-- [[ Init ]] --

do
	--// Setup UI Properties
	
	toolTipLabel.Size = UDim2.new(0.12, 0, 0.045, 0)
	toolTipLabel.BackgroundTransparency = 0
	toolTipLabel.Text = "I am Tooltip"
	
	toolTipLabel.Parent = container
	container.Parent = coreGUI
end

do
	--// Signal Connections
	
	runService.Heartbeat:Connect(updateToolTip)
end

I am doing my ToolTip in Widget. Since I want to show user, description of each item in the list.

Perhaps you want to try placing your ToolTip in CoreGui? Also, perhaps when the mouse enters a widget the new mouse location is not recorded. (Just a hypothesis though)

1 Like

I’ve used you solution, It did work, but it was only showing in the range of screen, but not the plugin widget. It must be possible since Roblox could achieve Tooltip in Toolbox which is Widget.

Late response sorry. I was watching a video to find an answer to the “But it is only showing in the range of the screen”.

Around 7:05

image

Widgets can only detect the mouse location and all other user input typesinside the 3D viewport that you usually interact with during playtime and such. This means you will not be able to detect where the mouse is when a user is navigating the Explorer or Output window or any other widget.

Within that video there is also this:

image

You unfortunately will not be able to make your own ToolTips in the fashion you are trying to due to the limitations of widgets, sorry!

Also ROBLOX might use their own internal “ToolTip” methods not exposed to the Lua front-end.

3 Likes