I want to have the player's name inside a textbox when they enter the game. I put this inside the textbox but its not working.
m = script.Parent
function onPlayerEntered(nP)
m.Text = "..nP.Name.."
end
I want to have the player's name inside a textbox when they enter the game. I put this inside the textbox but its not working.
m = script.Parent
function onPlayerEntered(nP)
m.Text = "..nP.Name.."
end
Lua can't read English. Defining a function doesn't make that function do anything -- it has no idea what onPlayerEntered is supposed to mean.
If you want it to happen, you need to tell ROBLOX when it should happen.
You can do this by connecting to an event (the most recent blog post is on this subject).
If this is a LocalScript, you could use .ChildAdded on the Players service; if this is a normal Script object, you could use .PlayerAdded:
game.Players.PlayerAdded:connect( onPlayerEntered )
This tells it to run onPlayerEntered whenever there's a new player.
You'll see that you just get the text saying "..np.Name.." -- you won't actually get their name. That's because you made this a string. Again, Lua doesn't read -- it just copies that text into place. If you want to show the expression which is their name, just remove the quotes:
m.Text = nP.Name
If you want to add something before or after, you can use the concatenation operator, ..
m.Text = "before" .. np.Name .. "after"
So that you would see, for example, "beforeBlueTaslemafter" if I joined.
Also note that when testing in Solo, it's possible your script will only start running after the player has joined, so you might need to test with a server to see anything.
This discussion is preserved as it was. New answers, comments, and votes are closed.