CharacterAdded event not firing

So I have the following piece of code and the CharacterAdded is not firing, is it because of the vertical order? I mean calling LoadCharacter() before declaring the CharacterAdded event.

game.Players.PlayerAdded:Connect(
	function(Player)
		
		local Profile = BaseProfile:Clone();
		
		Profile.Name = Player.Name
		Profile.Parent = Profiles
		
		PlayerId = Player.userId;
		local PlayerData = DataBase:GetAsync(PlayerId);
		DataSlots = Profile:GetChildren();
		
		if PlayerData then
			print("Data Received!")
			for Key, Value in pairs(DataSlots) do
				if PlayerData[Value.Name] then
					Value.Value = PlayerData[Value.Name]
				end
			end
			Player:LoadCharacter()
		else
			print("Data Missing")
		end
		
		Player.CharacterAdded:Connect(
			function(Character)
				print("Requesting")
				Weld.WeldSword(Character, Profile.Sword.Value)
			end
		)
	end
)
1 Like

Could you please send the output?

The output stays empty, Requesting doesn’t get printed, neither the print inside the module.

Considering the printing isn’t being printed, perhaps the PlayerAdded event isn’t firing. Might want to check that out.

A way you could check if that event isn’t firing is if you try using print prior to it.

Oh the PlayerAdded is firing, the output returns Data Received. I meant none of the prints inside the CharacterAdded event.

The character is loaded before you begin listening to the event (you :LoadCharacter() then listen for CharacterAdded), therefore the function won’t run.

You can solve this by performing the logic you want after you load the character, i.e:

local function CharacterLoaded(Player)
	local Character = Player.Character or Player.CharacterAdded:Wait()
	print(Character.Name .. " loaded!")
end

game:GetService("Players").PlayerAdded:Connect(function(Player)
	Player:LoadCharacter()
	CharacterLoaded(Player)
end)

image

9 Likes

Thanks! apparently my first thought was correct.

1 Like