PlayerAdded not running

PlayerAdded wont run for me in studio. I have to loop through every player at test start and then run a function on them instead of just using playeradded. Also, CharacterAdded has the same issue. Typically CharacterAdded would work for me and I wouldn’t have to get the player’s character when they join, but now I do.

Expected behavior

I expect my PlayerAdded to run regularly so I don’t have to run a function on existing players.

Can you send a picture of it a error code or something?

There is no errors. I found that the issue was my module loader, and the player running before the scripts, run. However, when I put PlayerAdded in the modulescript outside any other functions, it still doesn’t run, and it used to work just fine.

Not a bug, your player instance is already in game before the module runs.

local function playeradded(player)
	print('Hi')
end

game.Players.PlayerAdded:Connect(playeradded)
for i,v in game.Players:GetPlayers() do
	task.spawn(playeradded, v)
end

Do module scripts run differently to server scripts though? Like slower because it should work the same way since i put it outside the function

It’s only a question of if the script ran before the player actually joined, its a race condition. It’s always safer to handle it like @OnceCrowned pointed out