Username appearing over player when mouse hovers over it not working

Basically I have a script that hovers the players username over their torso when the clients mouse is hovered over them but it’s not working. There are no errors being outputted either. Could someone help me with the correct code? And the code is in a localscript in starterplayerscripts

Code:

local Tag = Instance.new("TextLabel",script.Parent)
	Tag.Text = ""
	Tag.Visible = false
	Tag.TextColor3 = Color3.new(1,1,1)
	Tag.Font = "ArialBold"
	Tag.FontSize = "Size18"
	Tag.BackgroundColor3 = Color3.new(0,0,0)
	Tag.BackgroundTransparency = 0.5
	Tag.TextXAlignment = "Left"
	 






local RunService = game:GetService('RunService')
local Players = game:GetService('Players')


local player = Players.LocalPlayer
local mouse = player:GetMouse()


local Selected = nil

RunService.RenderStepped:Connect(function()
	local target = mouse.Target
	if target then
		local humanoid = target.Parent:FindFirstChild('Humanoid') or target.Parent.Parent:FindFirstChild('Humanoid')
		if humanoid then
			Tag.Visible = true
			Tag.Text = target.Name
			Tag.Size = UDim2.new(0,Tag.TextBounds.X,0,20)
			Tag.Parent = humanoid.Parent
			Selected = humanoid.Parent
			
			end
		else
			if target == false then
				Selected = nil
			Tag.Parent = nil
			end
		end
end)

Setting a text label’s parent to a humanoid doesn’t work

You probably need to use a billboard Gui and set it adornee to the torso

1 Like

I suggest instead using the following script:

local TextLabel = script.Parent
local player = game:GetService("Players").LocalPlayer
local mouse = player:GetMouse()
local connection

local function CheckMouse()
	TextLabel.Position = UDim2.new(0, mouse.X + 10, 0, mouse.Y + 5)
	TextLabel.Visible = false
	local target = mouse.Target
	if target and target.Parent then

		if target.Parent:FindFirstChild("HumanoidRootPart") then
			connection = target.Parent:FindFirstChild("HumanoidRootPart").Changed:Connect(function(property)
				if property == "Position" or property == "Orientation" then
					CheckMouse()
					connection:Disconnect()
				end
			end)
			TextLabel.Text = target.Parent.Name
			TextLabel.Visible = true
		end

	end
end

mouse.Move:Connect(CheckMouse)

I hope this will work for you.
Note this script should be local and inside a TextLabel, else you gotta give it the path to the TextLabel which will be moved to your mouse.

I put the localscript inside of a text label. Where would I put the textlabel though?