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

What is wrong with this? Please Help!

Asked by 9 years ago

game.Players.PlayerAdded:connect(function(player) script.Parent.Text = player.Name .. " has entered" end)

Well, I was trying to make a script where, when a player entered, the text said:

player.Name .. " has entered"

I tried like 4 - 5 different types of ways to do this, but it just wasn't working out for me. I also tried to make it where, let's say you joined a game, and it said welcome then your name on the text, and for other people it said your name, and that you have joined. I couldn't figure that out either... Can you help me?

0
Can someone please answer this? theblodyninja109 0 — 9y

2 answers

Log in to vote
1
Answered by
4Bros 550 Moderation Voter
9 years ago

I don't see anything wrong with your code, but if you're using the playeradded event, make sure the script is a regular script, not a localscript. Also, make sure it's parented to gui/guiobject you want to change the text of. If you're using a localscript with a gui in it then you should have a serverscript that fires a remote event to a localscript which then changes the text of the gui everytime a player joins the game. (You can also use the childadded event in the player property if you're using a local script but i wouldnt really recommend it)

01--- If your script is a localscript parented under a gui
02-- Serverscript (regular script)
03local event = game:GetService'ReplicatedStorage':FindFirstChild'RemoteEvent'
04if not event then
05event = Instance.new("RemoteEvent",game:GetService'ReplicatedStorage')
06end
07game:GetService'Players'.PlayerAdded:connect(function(p)
08    event:FireAllClients(p.Name)
09end)
10 
11-- localscript parented under the gui
12repeat wait() until game.Players.LocalPlayer and game:GetService'ReplicatedStorage':FindFirstChild'RemoteEvent'
13local event = game:GetService'ReplicatedStorage':FindFirstChild'RemoteEvent'
14local gui = script.Parent
15 
View all 28 lines...
0
PlayerAdded works in a localscript? Nickoakz 231 — 9y
Ad
Log in to vote
0
Answered by 9 years ago

I don't think there is anything wrong with your code, but make sure you are NOT using a LocalScript with the PlayerAdded event.

01-- This code can only be used in a regular script.
02 
03tl= game.ReplicatedStorage.ScreenGuiOfEpicness.TextLabelOfFaith -- Change this to the TextLabel
04 
05function playerAdded(newPlayer)
06    tl.Visible = true
07    tl.Text = newPlayer.Name .. "has entered the server!"
08    wait(2)
09    tl.Text = ""
10    tl.Visible = false
11end
12 
13game.Players.PlayerAdded:connect(playerAdded)

As you can see, the code will obviously work. It's preferred to use BindableEvents to pass this onto another Script, which can then trigger this on each client.

Answer this question