Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How would i go about making the players name appear when the players mouse hovers over them?

Asked by 4 years ago
Edited 4 years ago

Here's My code

-- Get Service --
local RunService = game:GetService('RunService')
local Players = game:GetService('Players')

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

--Text Label--
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"



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.Text = target.Name
                Tag.Size = UDim2.new(0,Tag.TextBounds.X,0,20)
                Tag.Visible = true
            end
        else
                Tag.Visible = false
        end
end)

1 answer

Log in to vote
0
Answered by 4 years ago

It looks like in Line 27, you are trying to name the part of the player or the accessory. To fix that, you can simply :

Tag.Text = humanoid.Parent.Name -- Gets the name of the parent of the humanoid, aka, player

Lemme know if it helps!

Ad

Answer this question