local X = mouse.X
local Y = mouse.Y
if mouse.Target then
if mouse.Target.Parent:FindFirstChild("Torso") or mouse.Target.Parent:FindFirstChild("Humanoid") then
print(mouse.Target.Parent)
screenGui.Visible = true
screenGui.Position = UDim2.new(0, X, 0, Y)
screenGui.TextLabel.Text = mouse.Target.Parent.Name
else
screenGui.Visible = false
end
end
Its possible that its detecting accessories which are blocking the head and torso. Try it on an avatar with no hats and see what happens.
If hats are the problem, and an extra statement for if the part’s parent is an Accessory, and the accessory’s parent is a player model, then do whatever.
Instead of using RenderStepped, you could use the Move event of the Mouse object and check if the part’s a descendant of a player’s character.
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local screenGui = script.Parent.Parent:WaitForChild(“Frame”)
function isCharacter(target)
if target ~= nil then
for i, v in ipairs(game.Players:GetPlayers()) do
if v.Character ~= nil and target:IsDescendantOf(v.Character) then
return true
end
end
end
return false
end
mouse.Move:Connect(function()
local X = mouse.X
local Y = mouse.Y
local target = mouse.Target
if isCharacter(target) then
screenGui.Visible = true
screenGui.Position = UDim2.new(0, X, 0, Y)
screenGui.TextLabel.Text = target.Parent.Name
else
screenGui.Visible = false
end
end)
Try doing this to detect if the hit BasePart is part of a humanoid rig:
local target = mouse.Target
local model = target: FindFirstAncestorOfClass("Model")
if not model then -- Not a humanoid rig (part not under a model)
screenGui.Visible = false
return
end
local humanoid = model:FindFirstChildOfClass("Humanoid")
if not humanoid then -- Not a humanoid rig (part not under a model with a humanoid)
screenGui.Visible = false
return
end
-- If you want players only, add a check on model with Players:GetPlayerFromCharacter(model)
-- Got a valid target
print(model)
screenGui.Visible = true
screenGui.Position = UDim2.new(0, X, 0, Y)
screenGui.TextLabel.Text = model.Name
It works but the only issue which was stated by another person is that if you hover over an accessories name, it instead says that instead of the player name
local target = mouse.Target
-- Looks for the first model above the `target` BasePart
local model = target:FindFirstAncestorOfClass("Model")
if not model then -- Not a humanoid rig (part not under a model)
screenGui.Visible = false
return
end
-- Makes sure the model has a Humanoid
local humanoid = model:FindFirstChildOfClass("Humanoid")
if not humanoid then -- Not a humanoid rig (part not under a model with a humanoid)
screenGui.Visible = false
return
end
-- If you want players only, add a check on model with Players:GetPlayerFromCharacter(model)
-- Got a valid target and the humanoid model it's under, do stuff
print(model)
screenGui.Visible = true
screenGui.Position = UDim2.new(0, X, 0, Y)
screenGui.TextLabel.Text = model.Name
Maybe try using this code.
It looks above for the model of the humanoid rig, which has the name of the character. For example, if it gets an basepart in an accessory, it would look above the accessory for the model the accessory is under–instead of just getting the accessory. It then makes sure that model has a humanoid (meaning it’s a humanoid rig).
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local screenGui = script.Parent.Parent:WaitForChild(“Frame”)
function isCharacter(target)
if target ~= nil then
for i, v in ipairs(game.Players:GetPlayers()) do
if v.Character ~= nil and target:IsDescendantOf(v.Character) then
return v.Name -- Returns target name
end
end
end
return nil -- No target found? Return nil
end
mouse.Move:Connect(function()
local X = mouse.X
local Y = mouse.Y
local targetName = isCharacter(mouse.Target)
if targetName ~= nil then
screenGui.Visible = true
screenGui.Position = UDim2.new(0, X, 0, Y)
screenGui.TextLabel.Text = targetName
else
screenGui.Visible = false
end
end)
Alright. Now whenever it hovers over a user, it should show their name.