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

How do I get a players username on text by them touching a part?

Asked by 7 years ago

So I have a working morph, how do I make it so the text label above it shows the players username that is wearing the morph, and when the username removes when the player leaves the game. Help?

0
The player's Character has the name. Look through the parts that touched and find it's Parent. Usually the parent will be Character. MooMooThalahlah 421 — 7y

2 answers

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

Here I got something for you that my help... Don't ask me why I spent my time making this. xD I didn't have enought space to make everything look clean at the website, so evereywhere I put "--Here" means you got to bind together the text at the second line. I hope you understand some stuff that is in this thing. :D

01script.Parent.Touched:connect(function(hit)
02    if hit.Parent:FindFirstChild("Humanoid") then
03        if hit.Parent:FindFirstChild("OverHead") == nil then
04            local player = hit.Parent
05            local brickOverHead = Instance.new("Part", player)
06            local guiOverHead = Instance.new("SurfaceGui", brickOverHead)
07            local nameOverHead = Instance.new("TextBox", guiOverHead)
08 
09            brickOverHead.Name = ("OverHead")
10            brickOverHead.Anchored = true
11            brickOverHead.Transparency = 1
12            brickOverHead.CanCollide = false
13 
14            guiOverHead.Face = ("Front")
15 
View all 42 lines...

My suggestion to you is to go through all the code and figure out what's happening. :D This may help you understand more of the code and more of scripting in roblox.

I went the loooong way and made everything out of a script. The easiest way may be to make the SurfaceGUI with the text label ready and jut clone it into a character. Good luck with scripting!

~ TheWaterFoox

0
Thank you sooooo much! IPhoneDrew 9 — 7y
0
No problem. ;D TheWaterFoox 255 — 7y
Ad
Log in to vote
0
Answered by 7 years ago

To find the player name you can look for the right leg to touch the morph and then use parents and child to get to the group and add .Name to revive the name of the group that is the player.

Code Below Can Get The Name:

1script.Parent.Touched:connect(function(Hit)
2    if Hit.Name == 'RightLeg' then
3        print(Hit.Parent.Name)
4    end
5end

Answer this question