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

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

Asked by 10 years ago

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

Log in to vote
1
Answered by 10 years ago

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!

0
I will try this script until Raven replies. I am huge fan of RavenShields work tho. raystriker6707 30 — 10y
Ad
Log in to vote
0
Answered by 10 years ago

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)
0
Raven there is an error on line 6. - Disconnected event because of exception. It says that in output... raystriker6707 30 — 10y
0
I also got rid of the Frame. If that has anything to do with the error. raystriker6707 30 — 10y
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. Ravenshield 180 — 10y
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? raystriker6707 30 — 10y
0
it does not work DJH_100 28 — 5y
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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

Answer this question