CharacterAdded event doesn't always run

CharacterAdded event doesn’t always run

CharacterAdded hasnt run

What it should ALWAYS look like (CharacterAdded has run)

//Simplified Script

game:GetService("Players").PlayerAdded:Connect(function(plr)
        --Stuff here
	print("playeradded event ran")
	plr.CharacterAdded:Connect(function(character)

        --This may be the issue idk 
		if not character.Parent then repeat task.wait() until character end --detects if the character is inside workspace 

		print(character) --This doesnt always run

		local Humanoid = character:WaitForChild("Humanoid")
       --Stuff here
		print("characteradded event ran")

		Humanoid.Died:Connect(function()
			print("humanoid died event ran")

Thank you

I have to solution of your script:

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(character)
		local Humanoid = character.Humanoid
		Humanoid.Died:Connect(function()
			print("died")
		end)
	end)
end)
1 Like

I have currently tried this

character.AncestryChanged:Wait()

instead of

if not character.Parent then repeat task.wait() until character end --detects if the character is inside workspace

Still doesnt work

My script runs when the Character isnt in the workspace, thats the issue I believe

If i recall correctly. I did read somewhere some yrs ago that “CharacterAdded” doesnt sometimes fire because the character can load into the game before the signal has a chance to fire(Correct me if im wrong).

You could try to wait until the ancestry of the character has changed to make sure its not nil.

Modified bit of your code.

(Edit: Saw you already tried this example so idk then. Ill return to this topic later if it hasnt been solved because i dont have that much time on my hands atm.)

plr.CharacterAdded:Connect(function(character)
		if character.Parent == nil then
			repeat character.AncestryChanged:Wait() until character.Parent ~= nil
		end
		--This may be the issue idk 
		
		print(character) --This doesnt always run
		
		local Humanoid = character:WaitForChild("Humanoid")
		--Stuff here
		print("characteradded event ran")

		Humanoid.Died:Connect(function()
			print("humanoid died event ran")
		end)
	end)

I tried your solution, but the issue is still the same

(CharacterAdded doesnt run)

A “Fix” I used was to reload the character using Player:LoadCharacter, which would respawn the character. And should have the Event fire.

where would I place it in my script?

I would Recommend at the very bottom of the PlayerAdded function, where every event is connected, however its not guaranteed to always work.

You may need to create a custom loader for the Character by Disabling CharacterAutoLoads with the Players container.

plr.CharacterAdded:Connect(function(character)
        plr:LoadCharacter() -- like that?
		
		print(character) --This doesnt always run
		
		local Humanoid = character:WaitForChild("Humanoid")
		--Stuff here
		print("characteradded event ran")

		Humanoid.Died:Connect(function()
			print("humanoid died event ran")
		end)
	end)

Something like this?

Read Carefully on what I saaid.

Still doesnt work

game:GetService("Players").PlayerAdded:Connect(function(plr)
	
	print("playeradded event ran")
	plr:LoadCharacter() --Added this
	plr.CharacterAdded:Connect(function(character)
		
		if character.Parent == nil then
			repeat character.AncestryChanged:Wait() until character.Parent ~= nil
		end --detects if the character is inside workspace
		
		print(character)
		print(character.Parent)
1 Like

Anyway, If you are confused still.

@Herobrinekd1 might be correct, The Character may be loading in before the CharacterAdded Event is Connected, In order to Prevent this, you may need to ceate your own Character Loader, which would Involve waiting a bit, and then to Load the Character.

But, How do you Stop the Character from Loading in the Game?
game.Players has a Property called CharacterAutoLoads, which essentially allows for the character to Auto Repsawn, When we Disable this, the Character will not spawn, and we will now have to do this manually with Player:LoadCharacter, so what I recommend that you do is: Connect all the Events that will be used, This is so when the Load the Character, it will already have these properly set up to use, which would look like this:

Players.PlayerAdded:Connect(function(Player)
    -- Connect the 'CharacterAdded' Event
    -- Connect any other Event you might use

    Player:LoadCharacter() -- Do this at the very end of the Event
end)

But when the Character Dies, they will not Respawn, so you would need the Humanoid.Died Event to wait the amount for the RespawnTime, and then Load the Character

Humanoid.Died:Connect()
    task.delay(Players.RespawnTime, function() 
        Player:LoadCharacter() 
    end) 
-- Delays for the Amount of time in RepsawnTime and Reloads the Character
end)

This may help with CharacterAdded Working Properly.

1 Like

What do you mean exactly by other events you might use? Like the events I use within CharacterAdded or what exactly?

There are other Events like maybe CharacterRemoving as an Example.

You have changed the script but you are still playing in the same game.
Quit your game and save your script…

???
I modified the script and tried it?

Have you exit the game, fix your script and restart then?

You dont need to completely exit your game to Save a Script, you can Have it save Automatically either by closing the Script Tab, or when running the game.

1 Like

Yeah but if you watch the name script is the end is named (woitur Editing).
You must exit the script editor to save it. Personally is the case.