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

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

Asked by 10 years ago

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

Log in to vote
0
Answered by
Azarth 3141 Moderation Voter Community Moderator
10 years ago
-- LocalScript
local textButton = script.Parent
local me = game.Players.LocalPlayer
textButton.MouseButton1Click:connect(function()
    print("Hello there, "..me.Name)
end)

Ad
Log in to vote
0
Answered by 10 years ago

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
The best way is to use a LocalScript and use LocalPlayer. Azarth 3141 — 10y
Log in to vote
0
Answered by 10 years ago

You need to define what Username is. To do that, do this in a localscript:

local Username = game.Players.LocalPlayer

you can read about ontouched events for parts here. or else, click here to go to a page in the wiki explaining about LocalPlayer. hope this helped! Remember:

Always define something that the script/localscript can't recognize!

Answer this question