I want my script to work as the second a player joins the game

How do I make my script to work as the second a player joins the game

i think a function with OnPlayerJoin could do the trick, although don’t count on me for the answer.

you can connect a function to the Players.PlayedAdded signal.

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(Player)
    print(Player.Name + " just joined!")
end)

No such thing.

1 Like

You can use this script to check how many player or if there is how much player

repeat wait() until #game.Players:GetPlayers() > 2 it will yield the script then if there is more than 2 player it will execute the code below it

A better approach to something of that nature.

local Players = game:GetService("Players")

local Player1 = Players.PlayerAdded:Wait()
local Player2 = Players.PlayerAdded:Wait()

print("two players have joined")
1 Like

i already hav a script i just want to know where it should go

The one thing you’ll have to remember, though, is that it doesn’t work in Studio most of the time.

or even more simpler you could disable the script and then when #game.Players:GetChildren()==2 you could enable it and stick a debounce in so it only fires once.

wait i could just put a part at the spawn and when they step on it, it fires an event then i could receive it in a script and enable it

Yes but would you be confident it was the 2nd player?

ima do it a little different so it would not hav any errors

just remember that with scripts that it is disabled and not enabled i.e. script.disabled=true
good luck dude.

Another option is to do it with ReplicatedFirst if it is local.