Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to make textlabel's text appear as a players name?

Ok. So I am basically branching of of FastSnail5's question. But mine is different. How do you make the textlabel's text the players name when you hover over a player? Here is my script from RavenShield. I just don't know what to make the target or if I just have to change the whole entire script. (This is a local script)

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local target = game.Players -- Don't know what the target should be...
local label = player.PlayerGui.HoverGUI.Frame.TextLabel

mouse.Move:connect(function()
	if mouse.Target and mouse.Target:IsDescendantOf(target) then
		label.Text = target.Name
		label.Visible = true
	else
		label.Visible = false
		label.Text = ""
	end
end)

3 answers

Try this:

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local label = player.PlayerGui.HoverGUI.Frame.TextLabel

mouse.Move:connect(function()
local target = mouse.Target
if target and target.Parent and game.Players:FindFirstChild(target.Parent.Name) then
local otherPlayer = game.Players:FindFirstChild(target.Parent.Name)
label.Text = otherPlayer.Name
label.Position = UDim2.new(mouse.X, mouse.Y)
label.Visible = true
else
label.Visible = false
end
end)

That should work.

PLEASE UPVOTE IF THIS ANSWER IS GOOD!

1 comment

0

I will try this script until Raven replies. I am huge fan of RavenShields work tho.

You could've just messaged me, but I'll give a helping hand anyway.

What you want to do is take use of Mouse.Target, and see if Mouse.Target is child of either players' character. Assuming a player's character is built up by parts inside a model, you can take use of game.Players:GetPlayerFromCharacter(model) to verify if the target actually is a player. http://wiki.roblox.com/index.php?title=API:Class/Players/GetPlayerFromCharacter

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local label = player.PlayerGui.HoverGUI.Frame.TextLabel

mouse.Move:connect(function()
    if mouse.Target and game.Players:GetPlayerFromCharacter(mouse.Target.Parent) then
        label.Text = mouse.Target.Parent.Name
        label.Visible = true
    else
        label.Visible = false
        label.Text = ""
    end
end)

5 comments

0

Raven there is an error on line 6. - Disconnected event because of exception. It says that in output...

0

I also got rid of the Frame. If that has anything to do with the error.

0

Currently just on my mobile device, so I cannot test it. Try to print mouse.Target.Parent and game.Players:GetPlayerFromCharacter(mouse.Target.Parent). Any odd results? You could potentially also use game.Players:FindFirstChild(mouse.Target.Parent.Name), as bobafett3544 mentioned.

0

Well there are no errors for game.Players:FindFirstChild(mouse.Target.Parent.Name) but then again it does not work.When I put this in the command line, local player = game.Players.LocalPlayer local mouse = player:GetMouse() mouse.Target and mouse.Target:GetPlayerFromCharacter(mouse.Target.Parent). The output says "Error in script: '=' expected near 'and'." Does this help?

0

it does not work

bruh idk why u put so many lines, make a textlabel in your screengui and make a local script into the textlabel and just put this:

local player = game.Players.LocalPlayer.Name

script.Parent.Parent.TextLabel.Text = player

oh and bro, i just tried to help you make a little script if u want something advanced sorry but that's how it worked for me

This discussion is preserved as it was. New answers, comments, and votes are closed.