CharacterAdded event doesn't always run

Not Exactly true either, you can just simply set it so you can just run the game, and the Edits will Automatically Apply.

1 Like

so I would do LoadCharacter at the very end of my PlayerAdded function? Like this?

Players.PlayerAdded:Connect(function(Player)

Player.CharacterAdded:Connect(function(character)
local Humanoid = character.Humanoid

Humanoid.Died:Connect(function()
--delay stuff
end)

end)

Player:LoadCharacter()
end)

Or the LoadCharacter should be right before the CharacterAdded event?

You have it righht in this script.

Can you move the script to ServerScriptService?

You should structure your character added like this:

local function PlayerAdded(Player)
	
	local function CharacterAdded(NewCharacter)
		print(NewCharacter)
	end
	
	CharacterAdded(Player.Character or Player.CharacterAdded:Wait())
	Player.CharacterAdded:Connect(CharacterAdded)
end

game.Players.PlayerAdded:Connect(PlayerAdded)

This way character added will fire even if the character was already there

You could always use Character Appearance Loaded instead. I don’t personally, but that may fix the problem Player | Roblox Creator Documentation

I tried the script I sent in the message above with the LoadCharacter at the very very end of PlayerAdded and it seems to work.

Basically, I run the characteradded and humanoid.died events BEFORE actually loading the character to make sure the events actually connect to the character right?

Thank you for the help btw

1 Like

Player.CharacterAdded fires exactly when the Character is being created and parented, so that’s why race conditions like these show up.

You can fix this by setting workspace.SignalBehavior to Deferred or wrapping the callback inside task.defer:

Player.CharacterAdded:Connect(function(Character)
	task.defer(function()
		print(Character.Parent) -- Should always be 'Workspace'
	end)
end)

This should also void the need for polling. Anytime you use the if not A then Yield() until B statement, there’s probably a better solution you could do with events.

3 Likes

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