CharacterAdded event being fired twice on reset

The .CharacterAdded event is now being fired twice, first by a character which is parented to nil and second by the character parented to workspace. This doesn’t occur the first time it is fired.

game:GetService("Players").PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		Character:GetPropertyChangedSignal("Parent"):Connect(function()
			print(Character.Parent)
                        -- You can re-parent it to workspace to demo.
		end)
	end)
end)

Previously, the event was fired while the single character wasn’t a descendant of workspace. This worked fine, however the new behaviour is game-breaking.

image

This error is occurring because I am trying to load an animation into the dummy character. It is referenced with the following (from a tool):

local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
-- Logic...

This is the last in a long line of difficulties with the event, such as the R15 specific issue pointed out here.

There is no apparent specific cause. I have tested different character options, scaling methods, character accessories (meshes and no meshes), etc with the results staying the same.

demo.rbxl (17.5 KB)

6 Likes

you can fix this issue by making sure you wait for the new character after the reset. You can do this by changing line 4 of the LocalScript in the Tool to

local character = (plr.Character and plr.Character.Parent and plr.Character) or plr.CharacterAdded:Wait()

This is basically saying if the current character has no parent, it’s the old character, so we have to wait for the character added event to fire again to get the new character

3 Likes

Hey CalGamesDev, I have already implemented a work-around, it was relatively simple to do. The issue doesn’t lay in the difficulty to fix from the developers side, however from the (apparent) sudden change in behaviour which unexpectedly broke functionality I used to be relying on. I appreciate your suggestion though, especially if anyone finds this thread because they’re experiencing the same issue.

Are there any plans to change the behaviour? It appears to be new because I have been relying on it for a while without issue.

Thanks!

i’m not familiar with the issue, and what’s changed. I’ll make some inquiries about it though

1 Like

Hi all-- I think some ideas and issues are being conflated and confused here–Easy to do in the race
condition filled world of Roblox:

  • CharacterAdded event is not being fired twice–A Character’s Parent is changing twice–Different things.
  • A Character can have its Parent changed to nil showing that it’s obsolete
  • CharacterAdded Event can also be fired w/ Character Parent nil (but it WILL automatically update.)
    (Note this is not the same as the Parent being changed to nil after it already had a Parent.)
  • Maybe a nil Parent is being seen more often now–Prob. not a bug / typical breaking-change IMO
  • Using CharacterAdded directly (as opposed to relying on Character.Parent change) can uncomplicate
  • Code expecting that CharacterAdded will be fired twice is certainly not the way to go
4 Likes

I ran into the issue where CharacterAdded will fire twice on most occasions including startup. It commonly is fired again when respawning a player.

I read somewhere that the player.Parent when unused is set to nil. Respawning a player may result in 2 player characters, one with a parent and one set to nil.

To solve this issue you must check against player.Parent ~= nil like so

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(Player)
	player.CharacterAdded:Connect(function()
		if player.Parent == nil then return end

		-- do stuff here
	end)
end)