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

Why wont this player added thing work?

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

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)

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

1 comment

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.

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