Game.Players.PlayerAdded not firing?

This problem here is pretty simple. The event doesn’t fire or print or anything. Now, there’s no errors later in the code, and I have no clue why this would yield for long enough to prevent the code from running, as this is at the very start of the script.

local ui = script.SpawnUI
local template = ui.Main.Template
local statts = require(game.ReplicatedStorage.Modules.Stats)
local EN = require(game.ReplicatedStorage.Modules.EternityNum)
local statsSeen = 0

game.Players.PlayerAdded:Connect(function(plr)
	print("A")
	plr.CharacterAdded:Connect(function(char)
		print("B")
		task.wait(2)
		for i,v in char:GetDescendants() do
			if v:IsA("BasePart") then
				v.CollisionGroup = "BSKNPlayers"
			end
		end
		local UIthing = ui:Clone()
		for i,stat in UIthing.Main.Row1:GetChildren() do
			if stat.Name ~= "ListLayout" then
				stat.Stat.Value = plr.Stats:FindFirstChild(stat.statname.Value)
				if not stat.Stat.Value then
					stat.Stat.Value = plr.leaderstats:FindFirstChild(stat.statname.Value)
				end
				stat.statname:Destroy()
				stat.UpdateText.Enabled = true
			end
		end
		for i,stat in UIthing.Main.Row2:GetChildren() do
			if stat.Name ~= "ListLayout" then
				stat.Stat.Value = plr.Stats:FindFirstChild(stat.statname.Value)
				if not stat.Stat.Value then
					stat.Stat.Value = plr.leaderstats:FindFirstChild(stat.statname.Value)
				end
				stat.statname:Destroy()
				stat.UpdateText.Enabled = true
			end
		end
		for i,stat in UIthing.Main.Row3:GetChildren() do
			if stat.Name ~= "ListLayout" then
				stat.Stat.Value = plr.Stats:FindFirstChild(stat.statname.Value)
				if not stat.Stat.Value then
					stat.Stat.Value = plr.leaderstats:FindFirstChild(stat.statname.Value)
				end
				stat.statname:Destroy()
				stat.UpdateText.Enabled = true
			end
		end
		for i,stat in UIthing.Main.Row4:GetChildren() do
			if stat.Name ~= "ListLayout" then
				stat.Stat.Value = plr.Stats:FindFirstChild(stat.statname.Value)
				if not stat.Stat.Value then
					stat.Stat.Value = plr.leaderstats:FindFirstChild(stat.statname.Value)
				end
				stat.statname:Destroy()
				stat.UpdateText.Enabled = true
			end
		end
		for i,stat in UIthing.Main.Row5:GetChildren() do
			if stat.Name ~= "ListLayout" then
				stat.Stat.Value = plr.Stats:FindFirstChild(stat.statname.Value)
				if not stat.Stat.Value then
					stat.Stat.Value = plr.leaderstats:FindFirstChild(stat.statname.Value)
				end
				stat.statname:Destroy()
				stat.UpdateText.Enabled = true
			end
		end
		UIthing.Parent = char
		UIthing.Adornee = char:WaitForChild("Head")
	end)
	local skill = plr:WaitForChild("Stats").Skill
	local skillVis = plr:WaitForChild("leaderstats").Skill
	local Sstat = plr.Stats:FindFirstChild(statts.MainStat)
	if not Sstat then
		Sstat = plr.leaderstats:FindFirstChild(statts.MainStat)
	end

	if Sstat then
		Sstat.Changed:Connect(function()
			skill.Value = EN.toScientific(EN.log10(Sstat.Value))
			skillVis.Value = EN.short(skill.Value)
		end)
	end
end)

(Most of this code can be ignored, but I figured I’d include it for clarity’s sake. Also, all variables here are used, so I can’t remove them. neither A nor B print, and I tried replacing PlayerAdded with ChildAdded and also got nothing. I simply don’t know what’s going on here? Why would it yield for long enough to cause this?

If “A” doesn’t print:

  • One of these modules could hang the code just about for the event to connect after you join, not making it fire
  • This event doesn’t fire sometimes in Studio. Try in-game.

one of the modules you are requiring are likely yielding long enough that you join before the event connects or the module is hanging indefinitely

Thanks for the feedback! I’ll look for waits or loops in stats since I know EN doesn’t cause this, and afterwards I’ll check in a normal server.

Alright, It wasn’t hanging indefenitely, just a task.wait(0.2) was barely long enough to knock out the event. Thanks!

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