How to register when a new player joins the game

Hello, and thank you for checking in on this very simple question

I just returned from a very long coding break and I cant remember anything.
Instead of going back to my more complicated game i’m starting another, more simple one.

I want to register when a player joins to fire a command.

All I can remember is that it has to do with something along the lines of

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

This inst working however, anyone?

i think you forgot to put the

end) at the end

this is the full test code

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

      print("hi")

end)

oh well I don’t know then because I don’t go into scripting stuff since it’s too scary for me

Any errors in the output? Have you tried doing game:GetService("Players") in the event you renamed the Players service?

If it’s a Local Script then you can just do

local player = game.Players.LocalPlayer

print(player.Name .. ' Has joined the game!')

But if it’s a Server or “normal” script you can do.

game.Players.PlayerAdded:Connect(function(player)

    print(player.Name .. ' Has joined the game!')
end)

I recommend watching tutorials/reading the docs and doing research, this is very easy to do and you can easily find the answer to this just by googling it.

I wish you luck in the future with your scripting adventures. :slightly_smiling_face: