This is not Roblox’s fault. There is a chance that a player could connect prior to your script listening for PlayerAdded.
Instead, have a dictionary of players that have been loaded. For your use case, it could just be a player as a key, and a boolean as a value.
Then, make a function that sets up each Player with a Player parameter.
local playerMap = {}
function loadPlayer(player)
if playerMap[player] then return end
playerMap[player] = true
-- do your other stuff here
end
The purpose of this is to make sure you don’t call this function more than once for a player loading in. Really only pertains to the first player that joins the game.
Then, connect to PlayerAdded. Additionally, create a loop through the current players in the game as the script starts.
local Players = game:GetService(“Players”)
Players.PlayerAdded:Connect(loadPlayer)
for _, player in pairs(Players:GetPlayers)) do
loadPlayer(player)
end
You’ll also want to set up a function on PlayerRemoving that removes that entry from the playerMap table, but I’ll leave that to you.
Hope this helped. Sorry if there’s syntax errors, typed all this out on mobile.
This was an issue in Roblox studio because something which yields before the playeradded script is interfereing , Just loop through the player and add then to the function.
This isn’t weird, sometimes the player is already loaded before the script is, meaning the event isn’t fired.
I have it all the time in studio, just create a function and loop through players.