So I dont know why but my script was working fine and I ended the test then tried again and Player added just stops firing at all no matter what. Theres no errors in the script besides my whole entire game breaking because of this.
I even put a simple print (“Hi”) at the start of the player added event and It does not print.
ex:
game.Players.PlayerAdded:Connect(function(plr)
print("hi")-- nothing prints
end)
this is super frustrating and this issue also happens when i publish the game when this happened and if I joined the game (not in studio but on the website) this issue still happens.\
Is this in studio or the actual game? PlayerAdded may not fire in studio and you will need to loop through each player in the game after connecting the PlayerAdded event.
Dude I am very experienced with studio. You dont have to talk to me like I am one of the other newbie devs. And yes the script is in ServerScriptService. I just double checked.
Does the PlayerAdded event work inside of other scripts or just that specific one? If it’s just that one, please include the full script as it’s most likely something inside it causing the problem.
Nope. It happens with every Server Script in any Parent Workspace, Replicated Storage, ServerStorage etc. Even with a fresh new Server Script this still happens.
Interesting. It could be because your player is added before the script is actually executed; have you tried this with more than one person so the script has time to load in?
Here, try this script. I know it’s a bit overkill for something this simple but I get the service rather than indexing it directly, and I added the loop I mentioned earlier.
local Players = game:GetService("Players")
local function PlayerAdded(Player)
print(Player.Name)
end
Players.PlayerAdded:Connect(PlayerAdded)
for _, Player in pairs(Players:GetPlayers()) do
PlayerAdded(Player)
end
Alright, to test which change was the fix I suggest removing the for loop and trying that. If it prints, not using :GetService() was the issue. I honestly don’t know what the cause was though.
Alright, then it was because the player loaded before the event was connected. I still recommend using :GetService() when using any service just incase the service isn’t created when you access it.