Then the issue you’re having is that the Studio server started but didn’t run all of your server scripts yet…
You start a Play Test in Studio
Studio creates the server.
The barebones of the Studio server is up and running.
Studio starts adding the player.
The player got added.
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.
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…
Run the event for players that are joining the game after the script was able to run.
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.
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.
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.
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.