ROBLOX been acting weird lately?

Hey there,

I’ve came along some issues lately where the PlayerAdded function never gets fired, even though it’s in a Server script in ServerScriptService.

It’s insanely weird, nothing is interfering with the code.

Anyone experiencing this too? Some people in my Discord server have been having the same issue as far as I know…

5 Likes

For example this:

I load into my game:
image
Nothing.

I check my code:

1 Like

Sometimes it works, sometimes it really doesn’t.

Another example: I play tested again, and now I did load in.
image
image

It is insanely weird and this is driving me crazy. Anyone have an idea?

1 Like

Have you tried moving the .PlayerAdded:Connect code as far up the script as possible? There may be something yielding above it.

3 Likes

Also showing the script would help

3 Likes

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.

4 Likes

Mate, you accidentally put a wrong bracket there!

for _, player in pairs(Players:GetPlayers()) do

Ah amazing script on mob 10/10

2 Likes

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.

2 Likes

To clarify, does this only occur in Studio for you, or a live game?

If the latter, there’s probably some issue with your scripts.

However the former I believe can occur from time to time as both the back and frontend loads more or less simultaneously.

To check is this is the case, add a print out before you connect your Player Added Event to see if any players exist.

If their are, the event won’t fire as, it only occurs when a player joins, not already exists.

print(“any players?”, #game.Players:GetPlayers())
game.Players.PlayerAdded:Connect -- etc
4 Likes

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.

In-game it should work.

3 Likes

Thanks for everyone’s help! I have figured out the problem and used the advice you all gave me. Thank you so much! :smile:

2 Likes