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

onPlayerEntered change text?

Asked by
NotSoNorm 777 Moderation Voter
10 years ago

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

Log in to vote
1
Answered by 10 years ago

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)
Ad
Log in to vote
0
Answered by
M39a9am3R 3210 Moderation Voter Community Moderator
10 years ago
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)
0
Does it need to be a local script? NotSoNorm 777 — 10y
0
Can be any type of script. M39a9am3R 3210 — 10y
0
mk NotSoNorm 777 — 10y
0
And this thing was downvoted why? M39a9am3R 3210 — 10y
0
I don't know NotSoNorm 777 — 10y
Log in to vote
0
Answered by
MrFlimsy 345 Moderation Voter
10 years ago

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)
0
Its not working, I keep getting this output: UserId is not a valid member of Workspace NotSoNorm 777 — 10y
0
What line are you getting this error on? MrFlimsy 345 — 10y
0
I don't quite know, although it isn't printing my "stages" NotSoNorm 777 — 10y
0
If it isn't printing the First Stage, the problem is likely with your event. Try changing it to game.Players.PlayerAdded MrFlimsy 345 — 10y
View all comments (4 more)
0
Not working :( NotSoNorm 777 — 10y
0
Is this script inside a Gui? M39a9am3R 3210 — 10y
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? MrFlimsy 345 — 10y
0
Positive NotSoNorm 777 — 10y

Answer this question