game.Players.PlayerAdded Not Working

Im Making a Code where it does something where the function: game:GetService("Players").PlayerAdded Is Activated.
The Problem, is that Dont makes Nothing, Even If I make it Correctly.

Some Code example:

game.Players.PlayerAdded:Connect(function()
    print("a")
end)

Something I need to say, Is that the Script is Server-Sided. But that Dont really Matters, Because it Dont works Even If its on Client-Sided.

It would be Nice if Someone can Answer This, Thanks.

Is that your full script? If not, chances are that you have some asynchronous function before the connection is made, therefore not firing in time. If possible, please provide it as it will give us a better idea on how to navigate the issue.

Well, Im Made a Open Source Module Script that Needs the Player’s HumanoidRootPart.
Here is the Full Code:

local Module = require(6995411300)

game:GetService("Players").PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(Chara)
       Module.Load(Chara:WaitForChild("HumanoidRootPart"), true, true, true, 10)
    end)
end)

If there’s a Grammar Error On the Script Is Bc Is wrote it Here, Not in Studio.

Anyway the OutPut Don’t gives me anything.

local players = game:GetService('Players')

local pAdded = function(player)

end

for _, ok in next, players:GetPlayers() do -- looping existing players [specially if they have bad internet connection]
  pAdded(ok)
end

players.PlayerAdded:Connect(pAdded) -- using the event to log others
1 Like

I see. It’s probably because IIRC, calling an external module is going to yield the thread until something is successfully returned, you should make another thread that halts your .PlayerAdded function until the module is successfully required.

local runService = game:GetService('RunService')
local Module
coroutine.wrap(function()
   Module = require(6995411300)
end)()

game:GetService("Players").PlayerAdded:Connect(function(player)
    repeat runService.Heartbeat:Wait() until Module
    player.CharacterAdded:Connect(function(Chara)
       Module.Load(Chara:WaitForChild("HumanoidRootPart"), true, true, true, 10)
    end)
end)
2 Likes

Isn’t That the Problem, Even with a Printing Function Dont Works.

1 Like

So Much Thanks! That Actually Worked!

1 Like