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

I have this script to say "Hello there PLAYERNAME." but can't get it to work?

I don't know what I need to put for the ..username.. part.

textButton = script.Parent
textButton.MouseButton1Down:connect(function()
	print "Hello there"..username.."."
end)

3 answers

✓ Accepted answer
-- LocalScript
local textButton = script.Parent
local me = game.Players.LocalPlayer
textButton.MouseButton1Click:connect(function()
    print("Hello there, "..me.Name)
end)

You must define username.

The easiest way to access a user's username is to go through a string of parents. In this instance: script.Parent.Parent.Parent.Parent Because the script is a member of TextButton which is a parent of ScreenGui which is a parent of PlayerGui which is a parent of Player, which has a property called .Name. Here's a fixed script:

textButton=script.Parent
username=script.Parent.Parent.Parent.Parent.Name
textButton.MouseButton1Down:connect(function()
print "Hello there "..username.."."
end)

You can read more about GUI's here.

1 comment

1

The best way is to use a LocalScript and use LocalPlayer.

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