Characted Added not firing!?

First off, NO, I am NOT having issues with starting the game. It’s not that. I’m trying to simply detect when the character gets added and it’s not firing.

The code sample provided is in a local script:

function _G:BindPlayer(plr : Player | nil, inst, doNotBindChar)
	if plr ~= nil then
		local playerLeaveFunc = nil
		local playerCharAddedFunc = nil

		playerLeaveFunc = game:GetService("Players").PlayerRemoving:Connect(function(plrLeave)
			if plrLeave == plr then
				inst:Destroy()
				playerLeaveFunc:Disconnect()
				plr = nil
				playerLeaveFunc = nil
				playerCharAddedFunc:Disconnect()
				playerCharAddedFunc = nil
			end
		end)
		
		playerCharAddedFunc = plr.CharacterAdded:Connect(function()
			print('character added')
			print(doNotBindChar ~= true)
			if doNotBindChar ~= true then
				print('character added 2')
				inst:Destroy()
				playerLeaveFunc:Disconnect()
				plr = nil
				playerLeaveFunc = nil
				playerCharAddedFunc:Disconnect()
				playerCharAddedFunc = nil
			end
		end)
	end
end

Second off, NO, other topics, that I could find, are not helping me because it’s bloated by people who had issue with first spawns.

What I’ve tested so far:

  • Does the connection get made? Yes.
  • Does the function work by itself? Yes.
  • Is the Player nil? No.
  • Does running the function in the command bar work? Yes.

When you reset your character, does the event fire as expected? If so I believe the event is being connected after the character is already loaded.

This script is not located within the character, therefore this proposal isn’t relevant.

But to answer your question: Reseting yields the same result, it doesn’t work.
And, like I mentioned above, my issue isn’t related to first spawns or the character already being created. The event is just simply not firing when the character is added.

Ok I found a solution but now this just seems to be some form of engine issue.
I added a bindable function and updated the code to look like this:

script:WaitForChild('BindPlayerFunc').OnInovke = function(plr : Player | nil, inst, doNotBindChar)
	if plr ~= nil then
		local playerLeaveFunc = nil
		local playerCharAddedFunc = nil

		playerLeaveFunc = game:GetService("Players").PlayerRemoving:Connect(function(plrLeave)
			if plrLeave == plr then
				inst:Destroy()
				playerLeaveFunc:Disconnect()
				plr = nil
				playerLeaveFunc = nil
				playerCharAddedFunc:Disconnect()
				playerCharAddedFunc = nil
			end
		end)

		playerCharAddedFunc = plr.CharacterAdded:Connect(function()
			print('character added')
			print(doNotBindChar ~= true)
			if doNotBindChar ~= true then
				print('character added 2')
				inst:Destroy()
				playerLeaveFunc:Disconnect()
				plr = nil
				playerLeaveFunc = nil
				playerCharAddedFunc:Disconnect()
				playerCharAddedFunc = nil
			end
		end)
	end
end

function _G:BindPlayer(plr, inst, doNotBindChar)
	script:WaitForChild('BindPlayerFunc'):Invoke(plr, inst, doNotBindChar)
end

AND NOW, SOMEHOW, SOMEWAY. It works.