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

onPlayerEntered change text?

So when a new player joins I was hoping for it to put the players name on the text box, What am I doing wrong? Should it be local?

function onPlayerEntered(newPlayer)
	print("First stage")
script.Parent.Name1.Text = "Player:" p.Name = ""
print("Second stage")
end
game.Players.ChildAdded:connect(onPlayerEntered)

3 answers

Put this in a LocalScript.

game.Players.PlayerAdded:connect(function()
	print("First stage")
	script.Parent.Name1.Text = "Player:" ..game.Players.LocalPlayer.Name.. ""
	print("Second stage")
end)
function onPlayerEntered(newPlayer)
print("First stage")
script.Parent.Name1.Text = "Player:".. newPlayer.Name --All you needed to do was put .. to contract the string.
print("Second stage")
end
game.Players.ChildAdded:connect(onPlayerEntered)

5 comments

0

Does it need to be a local script?

0

Can be any type of script.

0

mk

0

And this thing was downvoted why?

0

I don't know

If you'd like to set Name1.Text to the player's name upon join, prefixed by "Player: " you will need to use the '..' operator.

function onPlayerEntered(newPlayer)
    print("First stage")
script.Parent.Name1.Text = "Player: "..newPlayer.Name --joins the string 'Player: ' with the name of the new player
print("Second stage")
end
game.Players.ChildAdded:connect(onPlayerEntered)

8 comments

0

Its not working, I keep getting this output: UserId is not a valid member of Workspace

0

What line are you getting this error on?

0

I don't quite know, although it isn't printing my "stages"

0

If it isn't printing the First Stage, the problem is likely with your event. Try changing it to game.Players.PlayerAdded

0

Not working :(

0

Is this script inside a Gui?

0

The only other issue I can think of is with the path of the object you're trying to change. Are you sure Name1 is the child of the script's parent?

0

Positive

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