Characteradded never works upon joining the game

wait(1)
game.Players.LocalPlayer.CharacterAdded:Connect(function()
	game.Players.LocalPlayer.Character:WaitForChild("Humanoid").Died:Connect(function()
print("died")
		currentcam.CameraType = Enum.CameraType.Custom
		end)
end)

the characteradded event never works upon joining the game for the first time, but works afterwards. There are other topics similar to this, but they don’t fit what I want. (character autoloads is true)

1 Like

That’s because your character spawns before your script registers the CharacterAdded event, and wait(1) is completely unnecessary and could be the reason for that.
The solution is to extract the function from the CharacterAdded event and call it if the Character already exists when the script runs:

local Player = game:GetService("Players").LocalPlayer

function RegisterCharacter(character)
	character:WaitForChild("Humanoid").Died:Connect(function()
		currentcam.CameraType = Enum.CameraType.Custom
	end)
end

Player.CharacterAdded:Connect(RegisterCharacter)
if Player.Character then
	RegisterCharacter(Player.Character)
end

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