PlayerAdded not working after requesting module

So I got this little bit of code, but the print lol doesn’t work only the got module.
It doesn’t print PlayerAdded

local Module = require(script.Parent.KentekenModule)
print("GOt module")

game.Players.PlayerAdded:Connect(function(plr)
	print("PlayerAdded:", plr.Name)
	local ken = Module:GetKenteken(plr)
	print(ken)
end)

This is due to race conditions. The script yields when requiring the module, therefore not being fast enough to get to PlayerAdded part before the player joins.
You need to check for any players who have joined before PlayerAdded runs:

local function PlayerAdded(plr) -- set up function
print("PlayerAdded:", plr.Name)
	local ken = Module:GetKenteken(plr)
	print(ken)
end

for i,v in game.Players:GetPlayers() do -- go through people already in game
PlayerAdded(v) -- fire PlayerAdded on each player
end

game.Players.PlayerAdded:Connect(PlayerAdded)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.