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 8 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 — 8y

2 answers

Log in to vote
1
Answered by
4Bros 550 Moderation Voter
8 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)

--- If your script is a localscript parented under a gui
-- Serverscript (regular script)
local event = game:GetService'ReplicatedStorage':FindFirstChild'RemoteEvent'
if not event then
event = Instance.new("RemoteEvent",game:GetService'ReplicatedStorage')
end
game:GetService'Players'.PlayerAdded:connect(function(p)
    event:FireAllClients(p.Name)
end)

-- localscript parented under the gui
repeat wait() until game.Players.LocalPlayer and game:GetService'ReplicatedStorage':FindFirstChild'RemoteEvent'
local event = game:GetService'ReplicatedStorage':FindFirstChild'RemoteEvent'
local gui = script.Parent


event.OnClientEvent:connect(function(arg)
    gui.Text = arg.. " has entered" 
end)
---

--- if you dont feel like doing all of that then
local gui = script.Parent
game:GetService'Players'.ChildAdded:connect(function(c)
    if c:IsA("Player") then
        gui.Text = c.Name.." has entered"
    end
end)







0
PlayerAdded works in a localscript? Nickoakz 231 — 8y
Ad
Log in to vote
0
Answered by 8 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.

-- This code can only be used in a regular script.

tl= game.ReplicatedStorage.ScreenGuiOfEpicness.TextLabelOfFaith -- Change this to the TextLabel

function playerAdded(newPlayer)
    tl.Visible = true
    tl.Text = newPlayer.Name .. "has entered the server!"
    wait(2)
    tl.Text = ""
    tl.Visible = false
end

game.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