game.Players.PlayerAdded not working

Then the issue you’re having is that the Studio server started but didn’t run all of your server scripts yet…

  1. You start a Play Test in Studio
  2. Studio creates the server.
  3. The barebones of the Studio server is up and running.
  4. Studio starts adding the player.
  5. The player got added.
  6. Your server script is finally done running and attached PlayerAdded.

This is why in Play Test in Studio, you’ll need to add a postcheck after adding PlayerAdded to see if any players are still in your game before the script was even able to fully run.

Would you like me to send you a repro fie and see if you can assess the situation?

As far as I know, Roblox Studio doesn’t wait for the server to load everything before starting to load the Player in Play Test yet.

You can use an alternative test method if you don’t want to add my additional function for whatever reason that will let you manually control players in your server by checking out the other Play Test tools that Roblox Studio provides…

I’ve suggested my solution as then you can continue using your typical Play Test method and the script will work just fine as my solution will…

  1. Run the event for players that are joining the game after the script was able to run.
  2. Run the event for players that are still in the game before the script was able to run.

If you want to keep your original code and not add my solution, your only other way of making sure a player is added after a Studio Server is completely made, you’ll need to use this feature.

image

This will start multiple studio instances, one to run as a locally dedicated server and other instances to run as players to connect to the server rather than a hybrid of Play Test.

I rather just suggest that you add the check for players that are still ingame before the script was able to run which by then, you’ve resolved your issue about game.Players.PlayerAdded not working 100% of the time in Studio Play Test.

So as a follow up.

If you need to test in Studio and PlayerAdded isn’t firing for your Play Test, your options are to either.

Add

function PlayerAdded(plr)
–[[do player things]]
end
game.Players.PlayerAdded:Connect(PlayerAdded)
for i,v in next,game.Players:GetPlayers() do
PlayerAdded(v)
end

so that your script can fire for when someone joins your game after your script ran.
and that your script can also capture everyone that joined your game before your script ran.

Or to use the other

Clients and Servers Studio testing tool.

1 Like

Yea, as far as I know you should just replace Players.Playeradded with game.Players.Playeradded , that’s the easiest way I think

I’m not sure what you mean…

He has

local Players = game:GetService(“Players”)

so

game.Players.PlayerAdded

is exactly the same as

Players.PlayerAdded

in his script…

1 Like

What if he redefines local Players as game.Players?

Exactly the same if he has his variable defined above to be game.Players or game:GetService(“Players”)…

There’s no difference.

1 Like

Well sometimes i change my script to something that seems like no difference but it still suddenly works lol

If you’re talking about PlayerAdded and again… using Play Test on Studio without just checking for players ingame after connecting a function for an event to PlayersAdded, you’re just playing roulette with if it’s going to run or not today.

It’s best to just add the event AND check for players that joined the game before the script was ran so that you will always get everyone, no matter what.

Seems like this should be Roblox scripting 101. I don’t understand why I had to search so hard to find this. Thanks for helping out here!

hahahah happy my post could help you!

4 years later. and it still works
image