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

Why wont this player added thing work?

Asked by 8 years ago

Why won't this work? Is the PlayerAdded right? Have I used the PlayerAdded right?

local plr = game.Players.PlayerAdded:connect(function(plr)
    if plr.Name == "jaxxcoolboy" then
        script.Parent.Text = "The founder jaxxcoolboy is in the game!"
    end
end)

2 answers

Log in to vote
0
Answered by 8 years ago
Edited 8 years ago

Your issue seems to be an obscure one which not even I knew about until now; when a player first enters (at least in Play Solo; not entirely sure), their name is set to Player1 before being set to the correct username. I found that simply adding a wait() fixed this.

game.Players.PlayerAdded:connect(function(plr)
    wait()
    if plr.Name == "jaxxcoolboy" then
        script.Parent.Text = "The founder jaxxcoolboy is in the game!"
    end
end)
Ad
Log in to vote
0
Answered by 8 years ago

No on PlayerAdded you don't want a variable so instead of

local plr = game.Players.PlayerAdded:connect(function(plr)

you'll want to do this

game.Players.PlayerAdded:connect(function(plr)

a function cannot be a variable if you want it to run. or you could do this

function onPlayerEntered()
--code
end

game.Players.PlayerAdded:connect(onPlayerEntered)

And always remember to put an end) if you're doing the first one

0
Well, in some cases, having that variable is necessary (if you want to later disconnect the event), but in this case it isn't. Forgot about that. IDidMakeThat 1135 — 8y

Answer this question